Home > Database > Mysql Tutorial > msyql中查询某个字段的不重复的所有记录_MySQL

msyql中查询某个字段的不重复的所有记录_MySQL

WBOY
Release: 2016-06-01 13:16:39
Original
940 people have browsed it

mysql> select * from a
;
+----+------+--------------+
| id | name | descri |
+----+------+--------------+
| 1 | a1 | 我是第一个a1 |
| 2 | a2 | 我是第一个a2 |
| 3 | a3 | 我是a3 |
| 4 | a1 | 我是第二个a1 |
| 5 | a2 | 我是第二个a2 |
+----+------+--------------+

5 rows in set

mysql> select a1.* from a a1 right join (select max(id) id from a group by name) a2 on a1.id = a2.id where a1
.id is not null;
+----+------+--------------+
| id | name | descri |
+----+------+--------------+
| 3 | a3 | 我是a3 |
| 4 | a1 | 我是第二个a1 |
| 5 | a2 | 我是第二个a2 |
+----+------+--------------+
3 rows in set

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template