SQL - DISTINCT Keyword


Advertisements

Previous Page Next Page

The SQL SELECT DISTINCT statement is used to select different (distinct) data from a database table. It eliminates any duplicate records and fetches only unique records.

Syntax

The syntax for using DISTINCT keyword is given below:

SELECT DISTINCT column1, column2, ....
FROM table_name;

Example:

Consider a database table called Employee with the following records:

IDNameCityAgeSalary
1JohnLondon253000
2MarryNew York242750
3JoParis272800
4KimAmsterdam303100
5RameshNew Delhi283000
6HuangBeijing282800

  • To fetch distinct Salary data of the employees present in the Employee table, the SQL code is:

    SELECT DISTINCT Salary FROM Employee;
    

    This will produce the result as shown below:

    Salary
    2750
    2800
    3000
    3100


Previous Page Next Page