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)
精彩评论