I have a MySQL database, and I would like to insert some values into one table, assuming that the specific value that I insert does not match the value in another table.
Here is a simplified / sample structure:
Table: invites
id : int (auto-increment index)
name : varchar
message : varchar
Table: donotinvite
name : varchar (index)
Is it possible to conditionally insert a pair of “name” and “message” into the “invites” table if the “name” does not match any “name” from the “donotinvite” table with one expression?
Something like this, maybe?
INSERT INTO invites
SET name = 'joe', message = 'This is an invite'
WHERE NOT EXISTS
(SELECT name
FROM donotinvite
WHERE name = 'joe')
source
share