开发者

Combining two table without duplicates

开发者 https://www.devze.com 2023-02-12 00:13 出处:网络
I have a table containing symbols: Table1 \'sym\' Ibm Msft SUnw Table 2 \'sym\' ABC BCD CDE IBM Using mysql: how could add the unique \'sym\' from table 2 int开发者_开发技巧o table 1.You coul

I have a table containing symbols:

Table1

'sym'
Ibm
Msft
SUnw

Table 2

'sym'
ABC
BCD
CDE
IBM

Using mysql: how could add the unique 'sym' from table 2 int开发者_开发技巧o table 1.


You could use distinct, and add a not exists condition to filter out the symbols already in Table1:

insert  Table1
        (sym)
select  distinct sym
from    Table2
where   not exists
        (
        select  *
        from    Table1
        where   sym = Table2.sym
        )


You can use the "not exists" test:

       insert t1
       (sym)
       select sym from T2 where not exists
       (select sym from T1 where T1.sym = T2.sym)
0

精彩评论

暂无评论...
验证码 换一张
取 消