When DISTINCT keyword in SQL is applied on a column it
returns the values of column eliminating duplicates. It is used to display the
distinct values.
SQL DISTINCT Syntax:
SELECT DISTINCT column1, column2…Column N from Table_name
Table
STUDENT:
Roll
number
|
First
Name
|
Last
Name
|
Department
|
Division
|
Address
|
Admission
year
|
Grade
|
1
|
John
|
Jones
|
Coms
|
A
|
New York
|
2005
|
Pass
|
2
|
Mike
|
Decoza
|
IT
|
A
|
London
|
2006
|
Fail
|
3
|
Ravi
|
Sharma
|
EE
|
B
|
Mumbai
|
2007
|
Fail
|
4
|
Ajay
|
Singh
|
Civil
|
C
|
London
|
2005
|
Pass
|
5
|
Amenda
|
Jones
|
Telecom
|
A
|
Manchester
|
2005
|
Pass
|
6
|
David
|
Cena
|
Coms
|
B
|
Liverpool
|
2006
|
Pass
|
7
|
Harmeet
|
Patel
|
IT
|
C
|
Mumbai
|
2005
|
Pass
|
SQL DISTINCT Example:
SELECT DISTINCT Address from STUDENT
Above SQL query selects only the distinct values from the
"Address" columns from the "STUDENT" table as below:
New York
|
London
|
Manchester
|
Liverpool
|
Mumbai
|
No comments:
Post a Comment