Monday 15 October 2012

DISTINCT

Distinct statement eliminates the duplicate data in the specified column from the table.

In a table, some of the columns may contain duplicate values. Sometimes you will want to list only the different (distinct) values in a table.

The DISTINCT keyword can be used to return only distinct (different) values.
 
DISTINCT Syntax:-
 
SELECT DISTINCT <Column_Name> FROM <Table_Name>
 
DISTINCT Example:-
 
We have a table called “salestaxRate” and columns are SalesTaxRateID,  TaxType, TaxRate, Name, ModifiedDate  as shown below...


Now we want to select only the distinct values (Different Values) from the column named "TaxRate" from the table above.

We use the following SELECT statement:

SELECT DISTINCT TaxRate FROM salestaxRate

The result-set will look like this

No comments:

Post a Comment