SQL statement used by MySQL to query duplicate table data

Source: Internet
Author: User

SQL statement used by MySQL to query duplicate table data

MySQL queries duplicate data in a table. For example, to query records with duplicate bar codes in the table, the SQL statement is as follows:

SELECT GUIDE_BARCODE FROM checker_barcode

Group by GUIDE_BARCODE having count (GUIDE_BARCODE)> 1

The SQL statement used to query duplicate data is now available, but the SQL statement may be written as follows:

SELECT GUIDE_BARCODE FROM checker_barcode

Where COUNT (GUIDE_BARCODE)> 1

Group by GUIDE_BARCODE

The conditions after having are used as the where condition for query. However, when the count function is used as the where condition for query, the SQL syntax is incorrect because the first sentence about having function in W3School is:

The HAVING clause is added to SQL because the WHERE keyword cannot be used with the aggregate function.

That is to say, these five functions cannot be used with the where condition, but they can be used with having to query desired results.

Aggregate functions: mysql has five types of Aggregate functions: avg, count, sum, min, and max.

This article permanently updates the link address:

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.