Difference between DISTINCT and group by, distinctgroupby
Difference between DISTINCT and GROUP
> DISTINCT is used to retrieve duplicate items in the query results, while group by is displayed by group. The purpose of the former is to remove the same items in the results, and the latter is mainly used to group the results, often used together with clustering functions.
The DISTINCT operation only needs to find all the different values. The group by operation also requires preparation for other Aggregate functions. At this point, the group by operation should do more work than DISTINCT.
In addition, there is basically no difference between DISTINCT and group by (without clustering functions), and there is no obvious difference in execution efficiency;
Functions used with group by are: http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html
> Example:
SELECT studentId, SUM (score)
FROM studentScores
Group by studentId
The preceding sentence can be used to calculate the sum of scores of all students.
> Therefore, the two applications are actually different. To remove duplicate items, we recommend that you use DISTINCT.