I thought I read a nifty solution from rudy a couple of weeks ago but I can’t seem to find it.
I want to insert a new record to a table and get the last_insert_id but in the same query, I want to get the existing id if the recrd was already there.
here is how I currently insert and get last_insert_id
bazz, you’re thinking of INSERT with ON DUPLICATE KEY, and of course the ON DUPLICATE KEY requires that you have defined a unique key in the table other than the auto_increment
then getting the id whether the insert succeeded or not will depend on a second query which searches on the unique key