My aim
I'm trying to perform the following sql query:
INSERT INTO api(site,key) VALUES ('example.com','a-random-key') WHERE NOT EXISTS (SELECT * FROM api WHERE site='example.com');
In order to insert a new row with a site and a corresponding key if there isn't already one with that site (eg insert 'example.com' with the associated key 'a-random-key' if there isn't an other record with the site 'example.com').
What isn't working
I'm getting the following 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 * FROM api WHERE site='example.com')' at line 1
What I've tried
I've tried to perform the two queries separatedly, and they both work.
My question
How can I make the query work?