插入不重複數據

tag 表

id    name

1     標籤

2     標籤2

 

tag2表

id    name

1     美女

2     標籤

 

我要把TAG2表的數據插進Tag表中,

只插入不存在的“美女”,

已經存在的“標籤”則不用插入

 

insert into tag(name)

select tag2.name from tag2 where not exists (select 1 from tag where tag.name=tag2.name);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章