在工作中的使用MySQL的DISTINCT遇到了一点小坑,大概的现象为:

1、查询dede_scores表:select * from dede_scores,查询到的数据为:

MySQL的Distinct使用遇到的坑

 

2、如果使用查询语句去重integral字段:select distinct integral from dede_scores; 查询到的结果为:

MySQL的Distinct使用遇到的坑

3、如果使用查询语句去重titles、integral字段: select distinct titles, integral from dede_scores; 查询到的结果为:

MySQL的Distinct使用遇到的坑

我们要的去重效果没有出现;

原因:distinct关键字应用与所有的列而不仅是前置它的列,如果给出select distinct titles, integral ,除非指定的两个列都不同,否则所有的行都将为检索出来。

相关文章:

  • 2021-04-11
  • 2021-12-20
  • 2021-05-22
  • 2021-07-03
  • 2021-11-19
  • 2022-01-15
  • 2021-10-12
  • 2021-11-17
猜你喜欢
  • 2021-08-08
  • 2021-09-14
  • 2021-06-22
  • 2021-10-15
  • 2021-08-31
  • 2022-01-09
  • 2021-08-01
相关资源
相似解决方案