Difference between DISTINCT and group by, distinctgroupby

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.