mysql - value of SELECT COUNT(DISTINCT allcolumns) bigger than SELECT COUNT(1) -


i run following sql in mysql, , why 2 count show different results?

select count(1), count(distinct column1, column2, column3, column4, column5) distinctcount `parts_color`; 

the results are:

  • count(1): 647611
  • distinctcount: 647263

why?

your table parts_color must have duplicate values.

select count(1) similar select count(*) retains duplicate values , returns count.

when use distinct in query duplicate values discarded , hence value less count(1).


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -