[thelist] insert if select fails to find element

Alex Beston alex at deltatraffic.co.uk
Thu Nov 17 04:44:15 CST 2005

 oh ok. will give it a try in a min.

i just tried this one:

INSERT into word_list(word) VALUES ('$word') WHERE NOT EXISTS (SELECT 
word FROM word_list WHERE word = '$word')

but this:

You have an error in your SQL syntax; check the manual that corresponds 
to your MySQL server version for the right syntax to use near 'WHERE NOT 
EXISTS (SELECT word FROM word_list WHERE word = 'zymurgy')' at line 1


/scratches head


>>is there a way of putting all the work on the sql - something like
>>""INSERT into word_list(word) VALUES ('$word')" IF ('$word') NOT EXISTS";
>This is roughly the sql syntax you are looking for. I don't know whether it
>will work in mysql though - a quick look at the manual didn't turn anything
>up, so you might as well just try it and see what happens.
>IF NOT EXISTS (SELECT word FROM word_list WHERE word='$word') INSERT INTO
>word_list(word) VALUES ('$word');



  Current Location:
  KL, Malaysia

More information about the thelist mailing list