Non-Brand Data

Non-Brand Data

Module 6: WHERE and HAVING: filtering before and after GROUP BY

Let's learn when a condition belongs in `WHERE` and when it belongs in `HAVING`.

Cornellius Yudha Wijaya's avatar
Cornellius Yudha Wijaya
Sep 26, 2026
∙ Paid

WHERE filters rows before SQL creates the groups. HAVING filters the groups after SQL calculates COUNT, SUM, or another aggregate.

Both clauses can remove data, but moving a condition between them can change the question we answer. A status filter in WHERE might remove orders that should still be included in a customer’s total.

In this module, we’ll compare two similar requests. The first needs customers with at least two total orders and one delivered order. The second needs customers with at least two delivered orders.

Upgrade to continue with the remaining modules and keep the full set of course resources.


User's avatar

Continue reading this post for free, courtesy of Cornellius Yudha Wijaya.

Or purchase a paid subscription.
© 2026 Cornellius Yudha Wijaya · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture