Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get count of distinct values in SQL

I have a table with 23 total rows. One of the columns is called thing. There are only 11 distinct things out of the 23 total rows.

When I run:

SELECT DISTINCT thing FROM tablename WHERE condition

I correctly get 11 rows.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

However, when I run:

SELECT DISTINCT COUNT(thing) FROM tablename WHERE condition

I get 23 for the total count. However, I want to get 11, which is the count of the distinct things. How can I rewrite my query so that it gives me a total count of 11?

>Solution :

SELECT COUNT(DISTINCT thing) FROM tablename WHERE condition
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading