MySQL distinct remove duplicate records

Source: Internet
Author: User
Although distinct is a syntax for SQL and does not belong to MySQL, here is an example of MySQL.
After so many years of distinct, incredibly has been wrong. Always thought that distinct is the removal of duplicate fields, originally it is to remove duplicate records.

A repeating record is a record in which all fields are the same after distinct.

For example: Suppose that in a multi-store marketplace system, there is a table that records sales records that record every sale in each store. As follows:

Running the following query, and then comparing the results separately, it is not difficult to see that distinct is the removal of duplicate records.

First query select DISTINCT UID from Sale_log; The owner of the sale was screened out.
Second query select distinct uid,store_id from Sale_log; Screened out the different shops of shopkeepers with sales. It can be obvious that the result of this query is to filter out the same UID and store_id records, rather than I used to assume that as long as there are distinct keyword-modified fields, there will be no duplicate values.
Finally, again, distinct is acting on the entire query, not on the field immediately following it.

MySQL distinct remove duplicate records

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.