0

After I ran the INSERT ... ON DUPLICATE UPDATE query with PHP, I used .insert_id to find out the newly inserted row or founded row to do another insert onto another table. But sometimes, .insert_id would return 0 for no updates. I still need to locate the founded row even there is no updates. Are there any alternatives or I have to use another SELECT statement, whenever I got 0 form .insert_id. Thanks in advance.

xam
  • 452
  • 2
  • 7
  • 15
  • Please provide a sample of your code – Omari Victor Omosa Feb 22 '16 at 20:07
  • insert_id would only return an id if a record got inserted (e.g. NO update took place)... inserts can't return any data, so if you want the id of the row that got updated, you'd need to do a select with a `where` that matches the data that was inserted. – Marc B Feb 22 '16 at 20:09
  • Actually insert_id would return found record when update occurred. In my situation, there might not be any update, and I still needed the found record id. Are there any function(s) I can call upon, after the ON DUPLICATE UPDATE query, to identify the found record? If not then I would have do another SELECT query, and that's what I am trying to avoid. Thanks in advance – xam Feb 22 '16 at 20:28
  • I found [link](http://stackoverflow.com/questions/25195902/) same as my question, but no answer yet... – xam Feb 22 '16 at 22:37

0 Answers0