MySQL queries duplicate data in a table. For example, if you need to query records with duplicate bar codes in the table, add the HAVING clause in SQL because the WHERE keyword cannot be used with the aggregate function.
MySQL queries duplicate data in a table. For example, if you need to query records with duplicate bar codes in the table, add the HAVING clause in SQL because the WHERE keyword cannot be used with the aggregate function.
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 Aggregate functions include avg, count, sum, min, and max.
This article permanently updates the link address: