MySQL 查询去重

MySQL About 1,067 words

DISTINCT

  • distinct name是去除name字段的重复值,返回name字段列
select distinct name from user;

+-------+
| name  |
+-------+
| zs    |
| admin |
| loso  |
+-------+
  • distinct name,home是去除namehome共同重复的值并且返回
select distinct name,home from user;

+-------+-------+
| name  | home  |
+-------+-------+
| zs    | China |
| admin | China |
| loso  | China |
| zs    | xx    |
+-------+-------+

GROUP BY

select * from user group by name;
+----+-------+------+---------------------+--------+-------+----------+
| id | name  | age  | birthday            | gender | home  | isdelete |
+----+-------+------+---------------------+--------+-------+----------+
|  0 | admin |    0 | 2000-01-01 00:00:00 |        | China |         |
|  2 | loso  |   10 | 2000-01-01 00:00:00 |        | China |          |
|  1 | zs    |   10 | 2000-01-01 00:00:00 |       | China |         |
+----+-------+------+---------------------+--------+-------+----------+

LIMIT 1

ORDER BY时间字段 desc LIMIT 1`

SELECT * from org_phone_num WHERE `remove`=0 and phone = '073188872151' ORDER BY last_modified desc LIMIT 1;
Views: 2,634 · Posted: 2019-04-06

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh