Insert non-duplicate rows from one table to anothe

2019-08-12 06:44发布

I have two tables T1 and T2. I want to merge only those rows of T2 which is currently not there in T1 .

`Insert into T1 select * from (select * from T2 where id not in (select id from T1))`

Is there a better and faste way of achieving the same. ID column is unique across the table

标签: mysql insert
1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-08-12 07:25
Insert into T1 
select * from T2
where id not in (select id from T1)

You could also join but then you'd need another subselect since MySQL does not want to select from a table it inserts at the same time without using a subselect.

查看更多
登录 后发表回答