select distinct 语句详解

select distinct :当我们期望返回的数据不存在重复数据时(每一行的数据都不一样)

例如:表a

sql 复制代码
select distinct a.* from a -- 可以查询出所有的信息
select distinct a.id from a -- 可以查询出id不同的信息,则还是全部数据的id列(1,2,3,4)
select distinct a.name from a -- 可以查询name不同的的信息,则是三条数据(qqq,www,eee)

由以上例子,可以很好的理解 distinct 关键字的作用。

还有一种作用,当select distinct 'XXX' from table where xxx不返回结果时,则结果为空,由返回结果时,结果被替换成XXX。
sql 复制代码
select distinct 'XXX' from a where a.name = 'qqq' -- 结果列为XXX
select distinct 'XXX' from a where a.name = 'dfgd' -- 结果列为空
相关推荐
五岳1 小时前
分库分表数据源ShardingSphereDataSource的Connection元数据误用问题分析
java·mysql·爬坑
悄悄敲敲敲1 小时前
MySQL表的约束
数据库·mysql
鼠爷ねずみ1 小时前
SpringCloud前后端整体开发流程-以及技术总结文章实时更新中
java·数据库·后端·spring·spring cloud
九皇叔叔2 小时前
MySQL 数据库 Read View 详解
数据库·mysql·mvcc·read view
Elastic 中国社区官方博客3 小时前
Elasticsearch:圣诞晚餐 BBQ - 图像识别
大数据·数据库·elasticsearch·搜索引擎·ai·全文检索
cui_win3 小时前
Prometheus实战教程 - Redis 监控
数据库·redis·prometheus
JIngJaneIL4 小时前
基于java + vue个人博客系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot
TG:@yunlaoda360 云老大4 小时前
华为云国际站代理商备份策略设置过程中遇到问题如何解决?
服务器·数据库·华为云
SelectDB4 小时前
Doris Catalog 已上线!性能提升 200x,全面优于 JDBC Catalog,跨集群查询迈入高性能分析时代
数据库·数据分析·apache
TAEHENGV4 小时前
进度跟踪模块 Cordova 与 OpenHarmony 混合开发实战
android·javascript·数据库