Is it possible to insert a row, but only if one of the values already in the table does not exist?
I\'m creating a Tell A Friend with referral points for an eco
A slight modification/addition to naeblis's answer:
INSERT INTO table (email) VALUES (email_address)
ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id)
This way you don't have to throw email=email_address
in there and you get the correct value for LAST_INSERT_ID()
if the statement updates.
Source: MySQL Docs: 12.2.5.3