I got this error and I'm not sure how to work with it. Simple explanations would be much appreciated. Error:
1140: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause - SELECT
records_found
FROM (emails
) WHERE
If you want to use aggregate functions (MIN, MAX, COUNT), you need to provide MySQL with information on which columns to perform the aggregation on. For example in your case you should use
to get number of rows with each of the email addresses, or if you're simply looking for a number of rows with a given address do this:
You have email in the output, but you are not grouping by it. You most likely want to remove the email column from the output since you have it in the WHERE clause:
SELECT COUNT(*) AS records_found FROM (emails) WHERE email = 'Email Address'
You can't use aggregate functions (like count(*)) with non-aggregated columns (like email) unless you include a group by clause. I'm assuming you are intending to try and get the count of each distinct email in the emails table, which would require a group by clause added to your query, like this:
Given that you are using a where clause that will ensure a distinct single email, you may be wondering why it's required - you can alternatively simply add an aggregate function around the email column as well since you know it is distinct: