[英]mysql select records in difference between two tables
I just create a federated table (cron_task_sync) get the updated data from server. 我只是创建一个联合表(cron_task_sync)从服务器获取更新的数据。 So now I want to update the outdated table (cron_task) in my local mysql database with that table. 所以现在我想用该表更新本地mysql数据库中的过时表(cron_task)。
Any sql can do this? 任何SQL可以做到这一点? I found there's a lot of limitation when I use mysql. 我发现使用mysql时有很多限制。 For instance except cannot be used. 例如,不能使用除外。
I am sure that that two table are in the same structure. 我确定两个表的结构相同。 Please help me. 请帮我。
If you have a primary key, like id
, you could use not in
: 如果您有一个主键(如id
,则可以在中使用not in
:
insert into cron_task
(id, col1, col2, col3, ...)
select id
, col1
, col2
, col3
from cron_task_async
where id not in
(
select id
from cron_task
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.