Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBruno Calheira
12,625 PointsWhen should I use HAVING in SQL Statements?
What's the difference between the "HAVING" and "WHERE" keywords in SQL Statements?
When should I use one or another in a SELECT?
2 Answers
Andrew Chalkley
Treehouse Guest TeacherThe HAVING clause is equivalent of the WHERE clause when your queries are aggregate functions.
I mention the subtle differences in this video.
Bruno Calheira
12,625 PointsThanks Andrew!
Adiv Abramson
6,919 PointsAdiv Abramson
6,919 PointsIn the video (2:20) the HAVING clause is used on a SELECT statement
SELECT first_name, UPPER(last_name), LOWER(email), LENGTH(username) AS username_length FROM users HAVING username_length < 19;
How does that even compile? There are is no GROUP BY clause in the statement.