
Hi Tom,
Yes, exactly â WHERE always comes before GROUP BY in SQL.
Hereâs why: the WHERE clause filters the rows before any grouping happens. So only the rows that match your condition are included in the groups.
Letâs say you have this query:
SELECT department, MIN(age) AS min_age, MAX(age) AS max_age
FROM Employees
WHERE department <> 'Marketing'
GROUP BY department;
First, SQL filters out all rows where the department is 'Marketing'. Then it groups the remaining rows by department and calculates the min and max age for each group.
If you applied the WHERE after GROUP BY, it wouldnât work â because WHERE doesnât operate on groups. Thatâs what HAVING is for, if you ever need to filter after grouping.
So yes, WHERE always comes first.
If you have more questions, I am here to help.








