views:

20

answers:

1

I have a SQL Server 2008 database with millions of records. One field has values ranging from 0 to 250 and may, or may not, include all numbers witin the range. How do I query the database to get a list of distinct values and the number of records contaiing that value?

I used a Select Count(Distinct) query but that only gives me the number of distinct values.

+6  A: 

You want to use the GROUP BY clause:

SELECT
  column1,
  COUNT(*)
FROM
  table
GROUP BY column1
Dean Harding
OMG Ponies
After I posted the question I thought the solution may involve GROUP BY but didn't see how to tie it together. Thanks!
Scott