SQL Select Distinct Statement
The Select Distinct statement is used to select or fetch only the (different) Distinct data from a database table. There are many duplicate values present in the database table, so Distinct is used to list different values.
SELECT DISTINCT Syntax :
The syntax of the SELECT DISTINCT statement is −
SELECT DISTINCT column1, column2, ... columnN, FROM table_name;
SELECT DISTINCT Example :
Consider the Customer table with the following records -
CustomerID | CustomerName | Age | Address | CustomerSalary |
---|---|---|---|---|
1 | Aarav | 28 | Udaipur | 28000 |
2 | Vivaan | 25 | Mumbai | 30000 |
3 | Reyansh | 28 | Chennai | 35000 |
4 | Muhammad | 24 | Udaipur | 50000 |
5 | Sai | 30 | Mumbai | 27000 |
Test Case:-The following code is an example, which would fetch the DISTINCT Address fields of the Customer available in CUSTOMERS table.
SELECT DISTINCT Address FROM Customer;
The result for the respective sql query is as follows −
Address |
---|
Mumbai |
Chennai |
Udaipur |
Exercise:-
1. ____ _____Country FROM Customers;
View Answer
2. SELECT * FROM Customers ______ _____ = _____;
View Answer
Visit :
Discussion