I\'m using ON DUPLICATE KEY UPDATE to handle duplicate inserts on a table, in order that they are discarded.
ON DUPLICATE KEY UPDATE
In my case it\'s a simple table storing tags:
You could add a third column ModifiedDate and use that:
ModifiedDate
insert into t(id, tag) select id, tag on duplicate key update ModifiedDate = now();
This will ensure that an update really occurs, and in turn, that LAST_INSERT_ID() returns a value.
LAST_INSERT_ID()