I have tried the following query:
INSERT INTO `surfed_site` (user, site)
VALUES ('123', '456')
WHERE NOT EXISTS (SELECT site FROM `surfed_site` WHERE site=456)
But I keep getting a MySQL error:
1064 – 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 site FROM surfed_site WHERE site=456)’ at line 3
I have no clue what I’m doing wrong, would anybody be able to guide me?
INSERTstatements support two1 syntaxes: one that usesVALUES, and one that uses a query. You can’t combine them, and only the query syntax supportsWHEREclauses. So:SET. If you’re only inserting one record, this one is functionally equivalent toVALUES, but arguably more readable.