当前位置:Gxlcms > 数据库问题 > distinct mysql过滤重复记录

distinct mysql过滤重复记录

时间:2021-07-01 10:21:17 帮助过:17人阅读

代码如下:
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是不可能实现的。

但可以通过其他方法实现关于SQL Server将一列的多行内容拼接成一行的问题讨论

distinct mysql过滤重复记录

标签:保留   多行   指定   效率   images   问题   title   重复记录   返回   

人气教程排行