SQL EXISTS 关键字
EXISTS
EXISTS
命令测试子查询中是否存在任何记录,如果子查询返回一个或多个记录,则返回true。
以下SQL列出了产品价格低于20的供应商:
实例
SELECT SupplierName FROM Suppliers WHERE EXISTS (SELECT ProductName FROM Products WHERE SupplierId = Suppliers.supplierId AND Price < 20);运行实例»
实例
SELECT SupplierName FROM Suppliers WHERE EXISTS (SELECT ProductName FROM Products WHERE SupplierId = Suppliers.supplierId AND Price = 22);运行实例»