ANY & ALL
ANY 和 ALL 指令搭配 WHERE 和 HAVING 使用。
ANY:當有任何一個 subquery 的資料符合條件就回傳 trueALL:當有全部 subquery 的資料符合條件就回傳 true
當有任何一個 OrderDetails 的資料 quantity 等於 10 時,就會回傳 true 和 productName 的列表:
SELECT ProductName
FROM Products
WHERE ProductID = ANY (SELECT ProductID FROM OrderDetails WHERE Quantity = 10);
當有全部 OrderDetails 的資料 quantity 等於 10 時,就會回傳 true 和 productName 的列表:
SELECT ProductName
FROM Products
WHERE ProductID = ALL (SELECT ProductID FROM OrderDetails WHERE Quantity = 10);