小白学习oracle遇到的疑惑点:distinct
Oracle DISTINCT应用多列示例
看下面的order_items表,表的结构如下:
以下语句从order_items表中选择不同的产品ID和数量:
SELECT
DISTINCT product_id,
quantity
FROM
ORDER_ITEMS
ORDER BY product_id;
执行上面查询语句,得到以下结果:
在此示例中,product_id和quantity列的值都用于评估结果集中行的唯一性。
为啥这里边product_id没有被过滤掉重复值呢,不被过滤是不是直接distinct quantity就可以了?为啥还要distinct product_id呢?求解!
2021-12-13更新:
弄明白了,distinct product_id,quantity 是过滤这两个字段都重复的数据。