email_address
-------------
id
prefix
fqdn
Prefix and fqdn together form a unique key.
I would like to write a query which would do an insert, if the email address is not yet in the table. If the address is already in the table, it should return the id.
Is there a way of writing a query which behaves like INSERT INTO email_address(prefix, fqdn) VALUES (?, ?) ON DUPLICATE SELECT id as LAST_INSERT_ID WHERE prefix = ? AND fqdn = ?
would if it were legal?
Basically I want to do an INSERT or SELECT in one query.