DISTINCT
keyword
The distinct
keyword is used with SELECT
statement to retrieve unique values from the table. Distinct
removes all the duplicate records while retrieving records from any table in the database.
Syntax for DISTINCT
Keyword
SELECT DISTINCT column-name FROM table-name;
Example using DISTINCT
Keyword
Consider the following Emp table. As you can see in the table below, there is employee name, along with employee salary and age.
In the table below, multiple employees have the same salary, so we will be using DISTINCT
keyword to list down distinct salary amount, that is currently being paid to the employees.
eid | name | age | salary |
401 | Anu | 22 | 5000 |
402 | Shane | 29 | 8000 |
403 | Rohan | 34 | 10000 |
404 | Scott | 44 | 10000 |
405 | Tiger | 35 | 8000 |
SELECT DISTINCT salary FROM Emp;
The above query will return only the unique salary from Emp table.