This should, at least theoretically, work for you:
First expand the table to have an extra tinyint type column layout. Then you can use the following query when inserting / updating:
INSERT INTO yourtable (a, b) VALUES (1, 2) ON DUPLICATE KEY UPDATE id = LAST_INSERT_ID(id), dummy = NOT dummy
(I assume that column a has a unique index and there is a row with a = 1.)
Then you can get the identifier of a new row (in case of INSERT) or an existing row (in case of UPDATE) through
SELECT LAST_INSERT_ID()
source share