I have a following map table, with a unique key on the name column:
id | name
1 aaa
2 bbb
3 ccc
I want to get a newly created ID if I insert a new value to this table, like this:
INSERT IGNORE INTO map VALUES(null, 'ddd');
I know I can do this with getLastId()
function. But I also want to get ID if a name already exists, and getLastId()
function returns 0 in such case:
INSERT IGNORE INTO map VALUES(null, 'ccc');
Is this possible to do with one SQL, and without checking if a record exists, etc?