Resolved: Why not use names_count as part of HAVING condition?
In the SELECT statement, COUNT(first_name) is aliased as names_count. Why write the HAVING statement as COUNT(first_name) < 200, instead of HAVING names_count < 200?
Why would that not work?
Thanks for reaching out.
I understand your confusion. The actual execution of MySQL statements is a bit tricky. However, the standard does specify the order of interpretation of elements in the query. This is basically in the order that you specify, although I think
GROUP BY clause
ORDER BY clause
This is important for understanding how queries are parsed. You cannot use a column alias defined in a
SELECT in the
WHERE clause, for instance, because the
WHERE is parsed before the
SELECT. On the other hand, such an alias can be in the
ORDER BY clause.
Hope this helps.