美文网首页
mysql distinct去重

mysql distinct去重

作者: 无与凡想 | 来源:发表于2019-06-12 16:30 被阅读0次

在使用distinct时发现,select distinct name from t1;会去掉重复的id记录。但是如果想返回其它字段:

select distinct name,id from t1;时,会返回所有记录,即使name相同的记录。这是因为mysql中distinct默认会过滤掉之后的所有字段都重复的记录,即name和id两个字段都重复的记录。如果要查询有重复字段的记录,可以使用group by 字段名。注意:select 后要查询的字段,在group by之后应该全部写上。

相关文章

  • mysql distinct去重

    在使用distinct时发现,select distinct name from t1;会去掉重复的id记录。但是...

  • MySQL去重distinct

    在MySQL中需要查询表中不重复的记录时,可以使用distinct关键字过滤重复记录。 语法: select di...

  • DB

    1、Mysql去重 distinct关键字:SELECT DISTINCT d.id from user d; g...

  • mysql_distinct 去重

    distinct 作用域后面的连续多个字段 对性别进行去重 ,就剩下男和女 每一个用户都去过那些城市

  • 23《MySQL 教程》DISTINCT 去重

    前面小节介绍了如何使用 GROUP BY 对查询数据分组,并且 GROUP BY 能起到有效去重作用,本小节介绍如...

  • mysql 练习题

    MYSQL部分 1.概述Group by 和Distinct去重的区别? Group by: 分组,相同字段归为一...

  • MySQL常用命令(二)-DISTINCT、LIMIT、ORDE

    DISTINCT关键字 作用:指示MySQL只返回不同的值(去重);用法:放置在需要去重的列前面; DISTINC...

  • distinct()函数 去重

    distinct()函数 去重 8.0之前先排序 再去重 效率低 select distinct...

  • sql 函数 单词整理

    distinct —— 去重函数 select distinct depart from teacher; b...

  • MySQL

    in(a,b)包含not 非like "%a%" 模糊查找distinct 去重,如 count(distinct...

网友评论

      本文标题:mysql distinct去重

      本文链接:https://www.haomeiwen.com/subject/oqwlfctx.html