Mysql removes duplicates based on a field and displays information about other fields.

Source: Internet
Author: User
Does mysql deduplicate a field and display other field information? Recently, it was required that the deduplication function be performed based on the values of a column in the SQL statement, and information about other fields should be displayed. selectdistinctname and sorcefromtable are used, and the result shows that deduplication does not work, because MYSQL considers that sorce and name must be repeated at the same time to be removed .??? Google, repeated

Does mysql deduplicate a field and display other field information? Recently, a requirement is to deduplicate data based on the values of a column in the SQL statement and display the information of other fields. select distinct name and sorce from table are used. The result shows that deduplication does not work, because MYSQL considers that sorce and name must be repeated at the same time to be removed. ??? Google, repeated

Mysql removes duplicates based on a field and displays information about other fields.

?

Recently, one requirement is to remove duplicates based on a column value in the SQL statement and display information about other fields,
Using select distinct name, sorce from table, we found that deduplication does not work, because MYSQL considers that sorce and name must be repeated at the same time before removal.
??? Google, the final solution for repeated tests is as follows:
??? Select *, count (distinct name) from table group by name
??? If the SQL statement has conditions such as limit and order by, it must be placed behind group.
This achieves the goal of both removing duplicates and outputting more field information.

Record, with a memo, to help you.

Related Article

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.