Sql 通过比较两个表来提取缺少的行
e、 g 简化案例表:Sql 通过比较两个表来提取缺少的行,sql,Sql,e、 g 简化案例表: select count(1) from table_a; --> returns 5 results select count(1) from table_b; --> returns 4 results select count(1) from table_a, table_b2 b where b.id_ab like a.id_ab; --> returns 4 results select count(1) from table_a, tab
select count(1) from table_a; --> returns 5 results
select count(1) from table_b; --> returns 4 results
select count(1) from table_a, table_b2 b
where b.id_ab like a.id_ab; --> returns 4 results
select count(1) from table_a, table_b2 b
where b.id_ab not like a.id_ab; --> returns unexpected result
SQL:
select count(1) from table_a; --> returns 5 results
select count(1) from table_b; --> returns 4 results
select count(1) from table_a, table_b2 b
where b.id_ab like a.id_ab; --> returns 4 results
select count(1) from table_a, table_b2 b
where b.id_ab not like a.id_ab; --> returns unexpected result
尝试此操作(除外),但遇到错误
select a.id_ab from table_a a, table_b b except select a.id_ab from table_a, table_b2 b
where b.id_ab not like a.id_ab;
或者如何使用union来实现这一点?e、 g
(Select * from table_a except select * from table_b) Union All (Select * from table_b except select record_id from table_a);
预期结果:
多谢各位 使用下面的查询(添加了左外连接)
select a.id_ab
from table_a a
LEFT JOIN table_b b on a.id_ab = b.id_ab
where b.id_ab is null
它将获得表a中不匹配的数据
select count(1) from table_a, table_b2 b
where b.id_ab(+) = a.id_ab;
如果只需要缺少行,请使用下面的查询
select count(1) from table_a, table_b2 b
where b.id_ab <> a.id_ab;
但不像
SELECT col1,col2 from table_a
UNION
SELECT col1 from table_b
使用下面的查询(添加了左外部联接)
它将获得表a中不匹配的数据
select count(1) from table_a, table_b2 b
where b.id_ab(+) = a.id_ab;
如果只需要缺少行,请使用下面的查询
select count(1) from table_a, table_b2 b
where b.id_ab <> a.id_ab;
但不像
SELECT col1,col2 from table_a
UNION
SELECT col1 from table_b
谢谢你的传奇。很好用。谢谢你的传奇。工作完美。