Pages

Friday, June 3, 2011

SQL Count Distinct


SQL Count Statement is used to count the total number of records saved in a particular table. SQL Count Statement returns total records including duplicates.
SQL Count (*) Statement does not take any other argument such bas column name to evaluate the result. It counts all columns whether they have duplicates or nulls.
E.g.:
USE NORTHWIND
SELECT COUNT (*) FROM ORDERS

Above SQL Query will return 830.

SQL Count (ALL [Column Name]) Statement returns the number of records including duplicates but excluding null value columns
E.g.:

SELECT COUNT (ALL CUSTOMERID) FROM ORDERS


SQL Count (DISTINCT [Column Name]) Statement returns unique, non null records.
E.g.:
SELECT COUNT (DISTINCT CUSTOMERID) FROM ORDERS


Above SQL Query will return 89.

No comments:

Post a Comment