From reading the MySQL documentation, I can’t explain the difference between these two queries in phpMyAdmin:
SELECT * FROM f_ean GROUP BY ean HAVING type = 'media'
–> gives me 57059 results
SELECT ean, type FROM f_ean GROUP BY ean HAVING type = 'media'
–> gives me 73201 results
How can the result number of a query be different by only showing different columns?
You should be using
WHERE, notHAVINGif you’re trying to filter records.HAVINGis used to apply the filter after grouping and sorting have happened.Regardless, the issue lies with how MySQL uses
GROUP BY.GROUP BYshould be used with an aggregate; MySQL extends the functionality for convenience. You’re receiving different results because of the way it sorts and groups the columns.See extensions to
GROUP BY.