'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.
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 1:[1]
SELECT COUNT(DISTINCT thing) FROM tablename WHERE condition
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | tinazmu |
