Sunday, June 26, 2011

Counting Unique (Distinct) Records with SQL

Using SQL to count all records in a table:


select count(*) from MyTable


Using SQL to count all records in a table with unique/distinct values in a particular attribute:


select count(distinct MyId) from MyTable

No comments: