开发者

Combining two table without duplicates

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜