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;

A. DISTINCT SELECT
B. SELECT COUNT
C. SELECT DISTINCT
D. SELECT SELECT

View Answer


2. SELECT * FROM Customers  ______  _____ =   _____;

A. WHOSE City = 'Berlin';
B. WHEN City = 'Berlin';
C. WHY City = 'Berlin';
D. WHERE City = 'Berlin';

View Answer







Visit :


Discussion


* You must be logged in to add comment.