Select*fromstudent;+------+---------+---------+- ----------+|Id |Name |Address|Subject |+------+---------+--"/> Select*fromstudent;+------+---------+---------+- ----------+|Id |Name |Address|Subject |+------+---------+--">
Home >Database >Mysql Tutorial >How to filter out duplicate rows in the rows returned by MySQL?
This can be achieved by using the DISTINCT keyword in the SELECT clause. DISTINCT applies to all combinations of data fields specified in the SELECT clause.
We have the applied table "Student" DISTINCT keyword as follows -
mysql> Select * from student; +------+---------+---------+-----------+ | Id | Name | Address | Subject | +------+---------+---------+-----------+ | 1 | Gaurav | Delhi | Computers | | 2 | Aarav | Mumbai | History | | 15 | Harshit | Delhi | Commerce | | 17 | Raman | Shimla | Computers | | 20 | Gaurav | Jaipur | History | +------+---------+---------+-----------+ 5 rows in set (0.00 sec) mysql> Select DISTINCT Address from student; +---------+ | Address | +---------+ | Delhi | | Mumbai | | Shimla | | Jaipur | +---------+ 4 rows in set (0.00 sec) mysql> Select DISTINCT * from student; +------+---------+---------+-----------+ | Id | Name | Address | Subject | +------+---------+---------+-----------+ | 1 | Gaurav | Delhi | Computers | | 2 | Aarav | Mumbai | History | | 15 | Harshit | Delhi | Commerce | | 17 | Raman | Shimla | Computers | | 20 | Gaurav | Jaipur | History | +------+---------+---------+-----------+ 5 rows in set (0.00 sec) mysql> Select DISTINCT name from student; +---------+ | name | +---------+ | Gaurav | | Aarav | | Harshit | | Raman | +---------+ 4 rows in set (0.00 sec)
The above is the detailed content of How to filter out duplicate rows in the rows returned by MySQL?. For more information, please follow other related articles on the PHP Chinese website!