sql根据一个表查询的数据作为条件查询另一个表

代码格式如下:

 select *  from BillConsume where obId in (select obId from OpenBills where clearTheMarket is null or clearTheMarket=0)

要注意的是:in后面的查询语句必须是查询一个字段跟前面的表相对应的。比如要根据订单号orderID,OpenBills 这个表就需要查询到orderID这个字段,BillConsume这个表的条件就要判断orderID

原文地址:https://www.cnblogs.com/codeDevotee/p/7262079.html