当前位置: 代码迷 >> Oracle管理 >> 查询相等条件之外的数据?该如何处理
  详细解决方案

查询相等条件之外的数据?该如何处理

热度:24   发布时间:2016-04-24 05:53:47.0
查询相等条件之外的数据?
表A, a.id 表B,b.id
其中a.id与b.id字段值部分相等.
现求, a.id=b.id 不相等a表中的值(意思a表中字段a.id在B表中字段b.id,中不相等的那些值,(不显示a.id=b.id的所有值,而显示a.id!=b.id的所有值))
求SQL语法!

------解决方案--------------------
SQL code
select a.*   from awhere not exists(select 1   from b    where a.id=b.id)
------解决方案--------------------
SQL code
select a.*   from a   where a.id not in  (select id                            from b)
------解决方案--------------------
select * from a where a.id not in(select b.id from b);
------解决方案--------------------
select a.* from a
where not exists (select 1 from b where a.id=b.id);

select a.* from a where a.id not in(select b.id from b);

兩個都行,如果B表中資料較多,用exists.
  相关解决方案