SQL中的左连接以识别某些行



下表A:

<表类> Cust_id 代码 tbody><<tr>1101110211032201

两个条件:

  • cust_id必须在表B
  • (cust_id, code)不能在表B

带条件的查询几乎完全从人类语言翻译成SQL:

select *
from a
where cust_id in (select cust_id from b)
and (cust_id, code) not in (select cust_id, code from b);
  • 列表项

  • Hello其他解决方案使用存在


select a.cust_id, a.code
from TABLEA a  left   join TABLEB  b on 
a.cust_id=b.cust_id and a.code=b.code
where b.cust_id is null and exists( select * from TABLEB 
where cust_id=a.cust_id)

最新更新