对oracle中的特定列使用distinct

Using distinct for specific column in oracle

在 oracle 中可以进行 Followinq 查询

select DISTINCT(COLA), COLB 
from TABLEA

在此查询中,

  1. 此查询 returns COLA 和 COLB 组合的不同值吗?
  2. 如果此查询 returns 单独的 COLA 的不同值,那么所选 COLA 的 COLB 值应该是多少?
  3. 或者如果我们有多个具有相同 COLA 值的记录,这个查询会抛出错误吗?

在您的示例中,查询 returns COLA 和 COLB 组合的不同值。

检查语法:

请注意,DISTINCT/UNIQUE/ALL 只能放在 SELECT 之后和 select 列表中第一个表达式之前。

文档说:
https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_10002.htm

DISTINCT | UNIQUE

Specify DISTINCT or UNIQUE if you want the database to return only one copy of each set of duplicate rows selected. These two keywords are synonymous. Duplicate rows are those with matching values for each expression in the select list.

ALL

Specify ALL if you want the database to return all rows selected, including all copies of duplicates. The default is ALL.

上面的意思是,DISTINCT/UNIQUE 总是应用于整个 select 列表,而不是个别列