views:

33

answers:

1

Hi, I'm trying to add sequence of tags to a list subjects. I wouldn't make unique tag column field because I may have the same duplicate depending by the user language like in the example

table_houses
id          name                    location
1           Victoria's Home         New York
2           Black Mesa Lab          New Mexico
3           Tube                    London

table_tags
id          tag          id_subjects       language
1           garage       1                 it
2           garage       2                 fr
3           research     3                 en
4           lab          3                 en
5           laboratorio  3                 it
6           garage       1                 it <== how to avoid this duplicated INSERT like first row?

I've saw some example where people uses INSERT IGNORE INTO statement but I've got It works only with unique columns and it is used to skip duplicate errors.

Does exist some way to skip duplicate tags for the same language only?

+3  A: 

You need to create a unique key over both tag and language.

alter table table_tags add unique(tag, language);

Then you can use

insert ignore into ...
Phil Wallach
+1: My thoughts exactly about adding a composite unique constaint/index
OMG Ponies
works great, thanks!
Vittorio Vittori