mysql中去重 distinct 用法
来源:互联网 发布:jre1.8 源码下载 编辑:程序博客网 时间:2024/05/29 07:19
在使用MySQL时,有时需要查询出某个字段不重复的记录,这时可以使用mysql提供的distinct这个关键字来过滤重复的记录,但是实际中我们往往用distinct来返回不重复字段的条数(count(distinct id)),其原因是distinct只能返回他的目标字段,而无法返回其他字段,例如有如下表user:
用distinct来返回不重复的用户名:select distinct name from user;,结果为:
这样只把不重复的用户名查询出来了,但是用户的id,并没有被查询出来:select distinct name,id from user;,这样的结果为:
distinct name,id 这样的mysql 会认为要过滤掉name和id两个字段都重复的记录,如果sql这样写:select id,distinct name from user,这样mysql会报错,因为distinct必须放在要查询字段的开头。
所以一般distinct用来查询不重复记录的条数。
如果要查询不重复的记录,有时候可以用group by :
select id,name from user group by name;
转载出处:http://www.cnblogs.com/shiluoliming/p/6604407.html
阅读全文
0 0
- mysql中去重 distinct 用法
- mysql中去重 distinct用法
- mysql中去重 distinct 用法
- mysql中去重 distinct 用法
- MySQL的distinct 用法
- mysql - distinct的用法
- mysql distinct 的用法
- mysql中distinct用法
- MySql之distinct用法
- mysql distinct的用法
- MySql中distinct的用法
- MySql中distinct的用法
- MySql中distinct的用法
- MySQL关键字Distinct用法介绍
- mysql中distinct的用法
- MySQL 中 distinct 的用法
- mysql distinct 用法详解及优化
- mysql中select distinct的用法
- luoguP1063 能量项链
- 数据库连接池dbcp配置
- MaxCompute帮助创业公司中减轻MySQL存储压力
- [笔记分享] [Camera] 相机的一些名词解释
- 继续模块化,这次是ES6
- mysql中去重 distinct 用法
- 软件测试计划模板
- 引用类型---单体内置对象
- iOS | 小心NSTimer中的循环引用
- 软件架构模式转载
- UVA
- jumpserver堡垒机名词
- python实例(字符串判断)
- bzoj3676:回文串(manacher+SAM的parent树上倍增)