所以用这样一句SQL就可以去掉重复项了:

select * from msg group by terminal_id;

SQL中distinct的用法(四种示例分析)

示例1

select distinct name from A

执行后结果如下:

示例2

select distinct name, id from A

执行后结果如下:

实际上是根据“name+id”来去重,distinct同时作用在了name和id上,这种方式Access和SQL Server同时支持。

示例3:统计


select count(distinct name) from A;   --表中name去重后的数目, SQL Server支持,而Access不支持
select count(distinct name, id) from A;   --SQL Server和Access都不支持

示例4

select id, distinct name from A;   --会提示错误,因为distinct必须放在开头

其他

distinct语句中select显示的字段只能是distinct指定的字段,其他字段是不可能出现的。例如,假如表A有“备注”列,如果想获取distinc name,以及对应的“备注”字段,想直接通过distinct是不可能实现的。

最新文章

  1. Linux系统编程重要细节记录(持续更新中)
  2. 显示 Sql Server 中所有表或表中行的信息
  3. linux 多个python版本的切换
  4. 父类中“this” 指向问题
  5. 原生JavaScript实现mouseenter
  6. Chapter15:派生类
  7. New MVC World
  8. UiAutomator源码分析之UiAutomatorBridge框架
  9. Eclipse报错An internal error occurred during: "J2EE Component Mapping Update". java.lang.NullPointerException
  10. python六十四课——高阶函数练习题(一)
  11. OSI 协议
  12. 配置tomcat的开发环境
  13. C#和java之间的一些差异与共性
  14. c++运算符重载---20
  15. LeetCode--168--Excel表列名称
  16. 世界各国货币,C#数字货币计算
  17. 修改MVC默认的pageBaseType以添加功能
  18. Node.js 被分叉出一个项目 — Ayo.js,肿么了
  19. Codechef Observing the Tree
  20. bzoj 2453: 维护队列

热门文章

  1. CentOS 7防火墙的关闭与开启
  2. oracle 游标相关资料
  3. 20190712_mysql执行sql脚本语句_Failed to open file_error
  4. 第15.30节 PyQt编程实战:通过eventFilter监视QScrollArea的widget()的Paint消息画出scrollAreaWidgetContents的范围矩形
  5. 第14.11节 Python中使用BeautifulSoup解析http报文:使用查找方法快速定位内容
  6. jarvisoj flag在管理员手上
  7. CSS初识- 选择器 &背景& 浮动& 盒子模型
  8. PC微信[多开+免扫码+防撤回撤回提示+转存语音+自动收款+远程命令]
  9. 《Eroico》关卡与操作设计
  10. 学习笔记:舞蹈链 Dancing Links