SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value
What is the difference between having and where
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
wherefilters on theselect ... fromhavingfilters on the aggregate results from thegroup by ...So, looking at your example again:
Here,
WHERE column_name operator valuesays “Return results for table_name where‘column_name operator value’ is true”.
Only after all the results from these conditions are found, it groups by column_name.
Then
HAVING aggregate_function(column_name) operator valuesays “For the resulting aggregate groups, run ‘aggregate_function(column_name)’ and return only results where ‘aggregate_function(column_name) operator value’ is true.”