tags:

views:

36

answers:

2

Hi, i have a table 'tag_article_assoc' with [tagId,articleId] fields. i want to insert new tags for a specific article (lets say articleId=23) but skip records already in db. i am not sure on the right syntax, any ideas?

INSERT INTO wd_article_tag_assoc (tagId,articleId) VALUES ('$upTag','23') ON DUPLICATE KEY UPDATE... 

thanks S

A: 
INSERT IGNORE INTO wd_article_tag_assoc (tagId,articleId) VALUES ('$upTag','23')
Orsol
ok, thats fine, but i would like to check out the "on duplicate syntax"
Sotos
Is INSERT IGNORE doing not what you want?
Orsol
i do not think this is working orsol. there are still duplicates created.
Sotos
A: 

I suppose you have the tagId,articleId both as primary key in your database

INSERT INTO wd_article_tag_assoc (tagId,articleId) VALUES ('$upTag','23') ON DUPLICATE KEY UPDATE tagId=$upTag

You are welcome to read http://stackoverflow.com/questions/548541/insert-ignore-vs-insert-on-duplicate-key-update

ntan
you are right ntan. only the one was primary. thanks for the tip!
Sotos
you are welcome.I keep forgetting my too but with my new MAC i will try too do better
ntan