Distinct clause in MYSQL by R4R Team

MYSQL DISTINCT clause:
Distinct clause is used to remove the duplicate item from the tables.

Syntax:
SELECT DISTINCT
* FROM table_name
WHERE conditions;

We have a table 'employee'

SELECT * FROM employee;

emp_id emp_name department emp_salary
1 Aman D1 34000
2 Ram D2 43000
5 Sita D5 10000
3 Ramesh D3 20000
4 John D4 65000
5 Sita D5 10000

-In the above table , we have some duplicate record which we want to remove so we use DISTINCT clause here:

SELECT DISTINCT * FROM employee;

emp_id emp_name department emp_salary
1 Aman D1 34000
2 Ram D2 43000
5 Sita D5 10000
3 Ramesh D3 20000
4 John D4 65000



Leave a Comment: