MySQL返回结果集的行中如何过滤掉重复的行?

数据库数据库 2023-08-31 03:31:41 1037
摘要: 示例我们有已应用的表“Student”DISTINCT关键字如下-mysql>Select*fromstudent;+------+---------+---------+-----------+|Id|Name|Address|Subject|+------+---------+---------+------...

MySQL返回结果集的行中如何过滤掉重复的行?

示例

我们有已应用的表“Student” DISTINCT 关键字如下 -

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)

以上就是MySQL返回结果集的行中如何过滤掉重复的行?的详细内容,更多请关注其它相关文章!