SELECT * from TB_BSD_Product
where ProductID in (SELECT ProductID FROM TB_BSD_Product_H)
SELECT * from TB_BSD_Product a
where EXISTS (SELECT 1 FROM TB_BSD_Product_H b where a.ProductID=b.ProductID )
Exists语句不关心子查询返回的具体内容,因此用“exists(select 1 from)”来判断子查询是否返回记录。
Exists(select):若子查询的结果集非空时,exists()表达式返回true;子查询的结果集为空时,exists()表达式返回false。
Not Exists(select):若子查询的结果集非空时,not exists()表达式返回false;子查询的结果集为空时,not exists()表达式返回true。