MySQL查询去重

MySQL大约 1070 字

DISTINCT

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

+-------+
| name  |
+-------+
| zs    |
| admin |
| loso  |
+-------+
  • distinct name,home 是去除name和home共同重复的值并且返回
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;
阅读 292 · 发布于 2019-04-06

————        END        ————

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

昵称:
随便看看换一批