SQL DISTINCT keyword

The distinct keyword in SQL is used alongside the SELECT statement to retrieve unique values from the table. The Distinct keyword removes all the duplicate records while retrieving records from any table in the database.

 

Below is the syntax for distinct keyword

SELECT DISTINCT column-name FROM table-name;

 

Example using DISTINCT Keyword

Let’s also consider the Emp table. you can see in the table below, that there is an employee name, employee salary, and also their age.

More so, multiple employees have the same salary as shown in the table below; therefore, we can use the DISTINCT keyword to list down distinct salary amount which is currently paid to the employees.

 

eidnameagesalary
401Anu225000
402Shane298000
403Rohan3410000
404Scott4410000
405Tiger358000

 

SELECT DISTINCT salary FROM Emp;

 

So, therefore, the SQL query above will return only the unique salary from the Emp table.

salary
5000
8000
10000