Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

COUNT DISTINCT for multiple columns

Thorsten KettnerJul 13 2017 — edited Nov 26 2020
Well the title says it all. We can count distinct values such as in
select count(distinct col1) from mytable;
but when we want to count distinct column combinations, we must either clumsily concatenate values (and be very careful to choose the right separator):
select count(distinct col1 || '-' || col2) from mytable;
or use a subquery:
select count(*) from (select distinct col1, col2 from mytable);
So I am looking for something along the lines of:
select count(distinct col1, col2) from mytable;
I don't know whether the SQL standard allows multiple values for COUNT. If not, we might use tuples:
select count(distinct (col1, col2) ) from mytable;
or something similar.
Comments
Post Details
Added on Jul 13 2017
10 comments
139,447 views