sql 关于连接的问题

来源:百度知道 编辑:UC知道 时间:2024/05/09 12:24:07
我有两个表

A表和B表

A表有8条数据,2个关键字 (id,rq)

B表有10条数据,2个关键字(id,rq)

我现在要查出来A表中哪两条数据不在B表中.

请问这个该怎么写连接!?

select A.id from A left join B where B.id is null

A→B

left join 显示左边(A)的数据的全部,在A中有,在B中没有,则B中记录为空。所以如果B中出现空,那么肯定A中的ID在B中没有记录。

当然下面的select not in也是对的。

你的提问错了吧?是B表中那两条数据不在A表中吧?

ORACLE.
select b.id,b.rq from b where id not in(select a.id from a);

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

select * from b where id not exists (select 1 from a where id=b.id)

select * from A where id not in(select id from B) and rq not in(select rq from B)

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