查询两个相同表中不同记录,这样的SQL语句怎么写?

日期:2019-08-03 10:33:02 人气:1

查询两个相同表中不同记录,这样的SQL语句怎么写?

可以用求非交集的办法获取这些记录,写法可以多种多样,具体要视表结构和比对要求而定。 请参考下列例子: 假设A、B两表结构一样,选出两张表中id字段互不相同的记录 select * from A where not exists (select 1 from B where B.id=A.id) union all select * from B where not exists (select 1 from A where A.id=B.id); 说明:第一个子查询选出A表中未出现于B表里的记录;第
    A+
热门评论