ALL 关键字

在子查询前面使用 ALL 关键字来确定对返回的每个值的比较是否为 true。如果子查询不返回任何值,那么搜索条件为 true。(如果子查询不返回任何值,那么对于所有零值条件为 true 。)

下列查询列出了包含总价小于订单号 1023 中每个商品的总价的商品的所有订单的以下信息。

图: 查询

SELECT order_num, stock_num, manu_code, total_price
          FROM items
          WHERE total_price < ALL
          (SELECT total_price FROM items
          WHERE order_num = 1023);

图: 查询结果

  order_num stock_num manu_code total_price
              
              1003         9 ANZ            $20.00
              1005         6 SMT            $36.00
              1006         6 SMT            $36.00
              1010         6 SMT            $36.00
              1013         5 ANZ            $19.80
              1013         6 SMT            $36.00
              1018       302 KAR            $15.00