Hi David,

* David D Speck <[EMAIL PROTECTED]> [2006-06-18 06:25]:
> What would the most elegant way be to insert a name and address
> entry into the main table ONLY if it is not already there? I
> could see doing a SELECT WHERE lname = new_lname AND fname =
> new_fname, AND street = new_street, etc, and then aborting the
> INSERT if the SELECT returns a match. 
> 
> I just wondered if there was a neater way to accomplish this?

how about adding a UNIQUE constraint to your table?

    CREATE TABLE foo (
        fname TEXT,
        lname TEXT,
        street TEXT,
        UNIQUE( fname, lname, street )
    );

Trying to `INSERT` a duplicate row will then throw an error. If
you don’t care to know about dupes and just want to bung the
data into the table, use `INSERT OR IGNORE ...` so failure will
be silent.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

Reply via email to