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
INSERT statements support two1 syntaxes: one that uses VALUES, and one that uses a query. You can't combine them, and only the query syntax supports WHERE
clauses. So:
INSERT INTO `surfed_site` (user, site)
SELECT '123', '456' FROM (SELECT 1) t
WHERE NOT EXISTS (SELECT site FROM `surfed_site` WHERE site=456)
SET
. If you're only inserting one record, this one is functionally equivalent to VALUES
, but arguably more readable.