Lesson 24 of 30
HAVING
Today at the studio
The board does not want every genre, only the ones that matter: "the genres with more than one show", "departments that pay above the line". You try a WHERE with a COUNT and the database politely refuses.
The idea
WHERE filters rows before grouping, so it cannot use an aggregate. HAVING filters groups after they are made, so it can: HAVING COUNT(*) > 1.
Put it after GROUP BY. A good rule: conditions about single rows go to WHERE, conditions about groups go to HAVING.
Example
SELECT show_id, COUNT(*) FROM characters GROUP BY show_id HAVING COUNT(*) >= 4
Your turn
0 of 4 questions
Question 1 of 4
Which genres have more than one show? Show genre and the count.