SQL INSERT:跳过已存在的值

发布于 2024-09-07 03:23:12 字数 820 浏览 3 评论 0原文

我正在尝试将标签序列添加到列表主题中。 我不会创建唯一的 tag 列字段,因为根据用户语言,我可能有相同的重复项,就像示例中

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?

我看到的一些示例,其中人们使用 INSERT IGNORE INTO 语句,但我已经得到它仅适用于唯一的列,并且用于跳过重复的错误。

是否存在某种方法可以仅跳过相同语言的重复标签?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掀纱窥君容 2024-09-14 03:23:12

您需要为标签和语言创建一个唯一的密钥。

alter table table_tags add unique(tag, language);

然后你可以使用

insert ignore into ...

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 ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文