下面的例子返回订购了 23 号产品 20 件以上的顾客的列表：

USE northwind

SELECT orderid, customerid

FROM orderS AS or1

WHERE 20 < (SELECT quantity

FROM [Order details] AS od

WHERE or1.orderid = od.orderid AND od.productid = 23)

GO

下面的例子从表 order details 中返回每种产品订购数量最多的列表。请注意这里的相 关子查询和外层查询引用了同一个表，查询优化器通常把这当作一个子连接。

USE northwind

SELECT DISTINCT productid, quantity

FROM [order details] AS ordl

WHERE quantity = (SELECT MAX (quantity)

FROM [order details] AS ord2

WHERE ordl.productid = ord2.productid)

GO

运行结果：