Skip to content
Advertisement

Count only non duplicate values

I need a query to count only values that aren’t duplicates, is there any way to do this without subqueries or temp tables?

If I have a table like this:

I can’t use SELECT COUNT(DISTINCT quantity) because it returns 4. (89 | 40 | 32 | 29)

How can I return 2? (89 | 32)

Advertisement

Answer

Use a subquery:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement