Select*fromstudent;+------+---------+---------+- ----------+|Id |Name |Address|Subject |+------+---------+--"/> Select*fromstudent;+------+---------+---------+- ----------+|Id |Name |Address|Subject |+------+---------+--">

Home  >  Article  >  Database  >  How to filter out duplicate rows in the rows returned by MySQL?

How to filter out duplicate rows in the rows returned by MySQL?

PHPz
PHPzforward
2023-08-25 08:01:051252browse

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.

Example

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete