SQL中多字段主键的两个表对比,该怎么处理
SQL中多字段主键的两个表对比
A表:字段A1,A2,A3,A4
B表:字段B1,B2,B3,B4
其中A表的A1、A2构成主键
B表的B1、B2构成主键
并且A1=B1
A2=B2
现在A、B两个表的数据记录条数不一致,我想查询出哪些是不一致的数据,查询语句怎么写?
用IN和EXIST可以实现吗?
------解决方案--------------------
来个左链接查询看看 left join
------解决方案--------------------
select * from a,b
where a.a1=b.b1(+)
and a.a2=b.b2(+)
and (b1 is null or b2 is null)
------解决方案--------------------
select a.*
from a
full join b
on a.a1 = b.b1
and a.a2 = b.b2
where b.b1 is null
------解决方案--------------------
select a.*,b.* from a,b where a.A1=b.B1(+) and a.A2=b.B2(+)
A表:字段A1,A2,A3,A4
B表:字段B1,B2,B3,B4
其中A表的A1、A2构成主键
B表的B1、B2构成主键
并且A1=B1
A2=B2
现在A、B两个表的数据记录条数不一致,我想查询出哪些是不一致的数据,查询语句怎么写?
用IN和EXIST可以实现吗?
------解决方案--------------------
来个左链接查询看看 left join
------解决方案--------------------
select * from a,b
where a.a1=b.b1(+)
and a.a2=b.b2(+)
and (b1 is null or b2 is null)
------解决方案--------------------
select a.*
from a
full join b
on a.a1 = b.b1
and a.a2 = b.b2
where b.b1 is null
------解决方案--------------------
select a.*,b.* from a,b where a.A1=b.B1(+) and a.A2=b.B2(+)