1

Given this DB table:

A_column       B_column
---------------
A1      1
A1      2
A1      2

A2      1
A2      1
A2      1

A3      2
A3      3
A3      4
A3      5

How do I write SQL SELECT query to print out number of unique values in B_column per value in A_column, so output would be like this:

A1     2
A2     1
A3     4

I tried this, but doesn't seem to work properly:

SELECT A_column, count(B_column) FROM table GROUP BY A_column

1 Answer 1

2

Use distinct:

SELECT A_column, count(distinct B_column) FROM table GROUP BY A_column
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.