I have a MySQL database and I would like to insert some values into one table, assuming that a particular value that I am inserting does not match a value in a different table.
Here is a simplified/example structure:
Table: invites
id : int (auto-increment index)
name : varchar
message : varchar
Table: donotinvite
name : varchar (index)
Is it possible to do a conditional insert of a 'name' and 'message' pair into the 'invites' table assuming the 'name' does not match any 'name' from the 'donotinvite' table with a single statement?
Something like this, perhaps?
INSERT INTO invites
SET name = 'joe', message = 'This is an invite'
WHERE NOT EXISTS
(SELECT name
FROM donotinvite
WHERE name = 'joe')