DISTINCT Keyword:
It is used to fetch different values from a table. It removes duplicate records from the result set and used when there can be multiple duplicate tuples in a table.
Syntax:
SELECT DISTINCT columnname FROM tablename;
Example:
The below query will fetch different name and salary from Employee table as it will not return duplicate names.
SELECT DISTINCT(name),salary FROM Employee;
Name |
Salary |
---------- |
---------- |
Sam |
25000 |
Ashley |
35000 |
Robert |
25000 |
Chris |
25000 |
As we can see from the above example no duplicate names are fetched from the table just because of DISTINCT keyword used with name column.
0 Comment(s)