下表A:
<表类>
Cust_id
代码
tbody><<tr>1 101 1102 1103 2201 表类>
两个条件:
- 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)