比如在Northwind数据库中有一个查询为
SELECT c.CustomerId,CompanyName FROM Customers c
WHERE EXISTS(
SELECT OrderID FROM Orders o WHERE o.CustomerIDc.CustomerID) 这里面的EXISTS是如何运作呢?子查询返回的是OrderId字段,可是外面的查询要找的…
EXISTS
语法:
SELECT 字段 FROM table WHERE EXISTS (subquery);
参数:
subquery是一个受限的SELECT语句(不允许有COMPUTE子句和INTO关键字)
示例:
SELECT * FROM A WHERE EXISTS (SELECT 1 FROM B WHERE B.id …