Yeile
Yeile

Reputation: 761

Select Distinct multiple columns, count distinct

How do you select distinct, and count of distinct? I have a table:

col1    col2
 1       1
 1       0
 0       0
 0       1
 1       1
 0       0

And I'm trying to get this:

col1    col2    count
 1       1        2
 1       0        1
 0       0        2
 0       1        1

Upvotes: 0

Views: 552

Answers (1)

Himanshu
Himanshu

Reputation: 32612

You just need to use GROUP BY clause with multiple columns.

SELECT col1, col2, COUNT(*) FROM Table1
GROUP BY col1, col2

Upvotes: 1

Related Questions