Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Followinq query is possible in oracle

select DISTINCT(COLA), COLB 
from TABLEA

In this query,

  1. Will this query returns distinct values for the combination of COLA and COLB?
  2. If this query returns distinct value for the COLA alone, then what should be the COLB value for selected COLA?
  3. Or if we have multiple records with same COLA value, will this query throws error?
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
280 views
Welcome To Ask or Share your Answers For Others

1 Answer

In your example the query returns distinct values for the combination of COLA and COLB.

Examine the syntax: enter image description here

Note, that DISTINCT/UNIQUE/ALL can be only placed after SELECT and before of the first expression in the select list.

The documentation says that:
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.

The above means, that DISTINCT/UNIQUE is always applied to the whole select list, not to individual columns


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...