(3万错误,NO.3),mysql中查询数据用distinct去重复并且查多个字段
来源:互联网 发布:交换机端口流量不稳定 编辑:程序博客网 时间:2024/05/30 02:22
在MYSQL中查询去重复字段使用
message表
+----+------+--------+---------+------------+| id | user | title | content | lastdate |+----+------+--------+---------+------------+| 1 | pzp | biaoti | neirong | 2012-08-27 || 2 | pzp | p | pzp | 2013-04-08 || 3 | pzp | p | pzp | 2013-04-08 |+----+------+--------+---------+------------+
查询去重复字段user
select distinct user from message;这样得到只有一个字段的数据
+------+| user |+------+| pzp |+------+
但是想在去重复的基础上同事查询其他字段,自己想当然的这样写
错误语句:
select id,distinct user from message;select id,distinct(user) from message; select id from message where distinct user;
上网查询后的借鉴资料:http://hi.baidu.com/fcl06/item/fa6d78351896b2c02e8ec283
修正查询语句:
select id,group_concat(distinct user) as user from message;+----+------+| id | user |+----+------+| 1 | pzp |+----+------+自己多练习了一下,发现这样也能查询。
distinct 在前,其他查询字段在后。
select distinct user,id,title,content,lastdate from message;+------+----+--------+---------+------------+| user | id | title | content | lastdate |+------+----+--------+---------+------------+| pzp | 1 | biaoti | neirong | 2012-08-27 || pzp | 2 | p | pzp | 2013-04-08 || pzp | 3 | p | pzp | 2013-04-08 |+------+----+--------+---------+------------+
这样,字段顺序稍微变了下,但是不影响需要得到的结果。
所以最后自己总结两个查询去重复项的基础上查询其他字段的方法。
1.使用:select id,group_concat(distinct user) as user,title from message;
2.使用:select distinct user,id,title from message;
- (3万错误,NO.3),mysql中查询数据用distinct去重复并且查多个字段
- mysql数据库DISTINCT 去重复查询
- mysql查询字段数据不重复distinct及distinct的多字段操作
- mySQL大量数据中去重复查询
- 用DISTINCT过滤mysql数据库中重复的字段
- distinct去掉mysql中重复字段值
- distinct去掉mysql中重复字段值
- mysql中去除重复字段-distinct
- 用distinct在MySQL中查询多条不重复记录值
- 用distinct在MySQL中查询多条不重复记录值
- 用distinct在MySQL中查询多条不重复记录值
- 用distinct在MySQL中查询多条不重复记录值
- 用distinct在MySQL中查询多条不重复记录值
- 用distinct在MySQL中查询多条不重复记录值
- 用distinct在MySQL中查询多条不重复记录值
- 用distinct在MySQL中查询多条不重复记录值
- MySql中distinct的用法 查询出某个字段不重复的记录
- sql distinct 去重复 (mysql)
- SDK获取文件大小 读取文件内容
- class.forname的作用
- 自定义jlist item的简单实现
- j2ee获取web路径
- ios 通知
- (3万错误,NO.3),mysql中查询数据用distinct去重复并且查多个字段
- 设计模式面试——四种最常用的设计模式
- MPLAYER ,fedora下安装
- socket通信浅解
- Linux开发社区及资源汇总
- (转)【Android游戏开发十八】解放手指,利用传感器开发游戏!(本文讲解在SurfaceView中用重力传感器控制圆球的各方向移动)
- 乱序执行中 寄存器重命名(Register Renaming )技术介绍
- Eclipse开发调试ARM裸机程序(三)C语言LED_LINUX使用DNW
- 基于jquery的上传插件Uploadify的API中文说明及例题