0

My problem is similar to the one in this question: MySQL ON DUPLICATE KEY - last insert id?

I have a Tag table in MYSQL with three columns. tagid, tagname and topicid and another irrelevant table. I insert first into the irrelevant table and then when user selects a couple of tags, I use insert ignore to insert these tags into the tag table.

After insertion I do a select LAST_INSERT_ID() to get the tagid of the last inserted tag. But if it's a duplicate tag insertion is ignored and I end up with the id of the record inserted into the irrelevant table instead of a 0 value which I could have used to deduce that the last tag I inserted was a duplicate tag. Like the solution proposed in that question.

So my question is, how do I get the primary key of the tag record which already exists in this scenario after insert ignore?

Community
  • 1
  • 1
user17282
  • 497
  • 5
  • 13
  • The tag table will have really lot of records. I am expecting it to have around a million+ records eventually. So I prefer not to do a select tagid from tag where tagname = "tagname that I am trying to insert" – user17282 May 20 '15 at 00:09
  • See this post: http://stackoverflow.com/questions/778534/mysql-on-duplicate-key-last-insert-id – Turophile May 20 '15 at 02:18

0 Answers0