tags:

views:

619

answers:

2

Guys I'm trying to finish this query -> my tag field is set to UNIQUE and I simply want the database to ignore any duplicate tag.

INSERT INTO table_tags (tag) VALUES ('tag_a'),('tab_b'),('tag_c')
ON DUPLICATE KEY IGNORE '*the offending tag and carry on*'

or even this would be acceptable

INSERT INTO table_tags (tag) VALUES ('tag_a'),('tab_b'),('tag_c')
ON DUPLICATE KEY UPDATE '*the offending tag and carry on*'
+1  A: 

Mysql has this handy UPDATE INTO command ;)

edit Looks like they renamed it to REPLACE

REPLACE works exactly like INSERT, except that if an old row in the table has the same value as a new row for a PRIMARY KEY or a UNIQUE index, the old row is deleted before the new row is inserted

Byron Whitlock
Dood Im gonna need you to elaborate on that one?
Derrick
Thanks for your help and time, Ivan Nevostruev solution seem to do the trick for me
Derrick
+4  A: 

You need INSERT IGNORE:

INSERT IGNORE INTO table_tags (tag) VALUES ('tag_a'),('tab_b'),('tag_c')
Ivan Nevostruev
Thank you very much!
Derrick