Selecting COUNT(*) with DISTINCT
Selecting COUNT(*) with DISTINCT
Selecting COUNT(*) with DISTINCT
Re: Selecting COUNT(*) with DISTINCT
Count all the DISTINCT program names by program type and push number
```
SELECT program_type AS [Type],
Count(DISTINCT program_name) AS [Count],
FROM cm_production
WHERE push_number = @push_number
GROUP BY program_type
```
`DISTINCT COUNT(*)` will return a row for each unique count. What you want is [`COUNT(DISTINCT )`](http://msdn.microsoft.com/en-us/library/ms175997.aspx): evaluates expression for each row in a group and returns the number of unique, non-null values.
```
SELECT program_type AS [Type],
Count(DISTINCT program_name) AS [Count],
FROM cm_production
WHERE push_number = @push_number
GROUP BY program_type
```
`DISTINCT COUNT(*)` will return a row for each unique count. What you want is [`COUNT(DISTINCT )`](http://msdn.microsoft.com/en-us/library/ms175997.aspx): evaluates expression for each row in a group and returns the number of unique, non-null values.