The DISTINCT keyword eliminates duplicate records in a column from the result and returns only the Distinct values.
SELECT DISTINCT <Column_Name> FROM Table_Name;
SELECT DISTINCT [OrganizationLevel]
The first line of the above statement indicates that we are going to execute the SELECT statement in AdventureWorks2012 database. The SELECT statement fetches all the distinct values from the column OrganizationLevel.
- In the above example, [HumanResources] is the Schema name and [Employee] is the table. I will explain about schema in my upcoming tutorials. Do not get confused between these two.
- I am using square brackets to all the columns, Database, Schema and table names in the above example. This query works even without square brackets. But it is a good practice to include square brackets. Because, the query will fail if there is space in the Column/Table name.