---
title: "Discussion on \"SQL WHERE vs HAVING: Differences, Execution Order and When to Use Each (Tested Examples)\" | Hashnode"
description: "Discussion on \"SQL WHERE vs HAVING: Differences, Execution Order and When to Use Each (Tested Examples)\". WHERE filters individual rows before they are grouped, and HAVING filters whole groups after GROUP BY has run. That's why only HAVING can use aggregate functions such as SUM(), COUNT() and AVG(). Use"
url: "https://hashnode.com/posts/sql-where-vs-having/6af1f54fa38f05dd11b20cc7"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [SQL WHERE vs HAVING: Differences, Execution Order and When to Use Each (Tested Examples)](https://mfaysaldev.hashnode.dev/sql-where-vs-having?utm_source=hashnode&utm_medium=feed)

WHERE filters individual rows before they are grouped, and HAVING filters whole groups after GROUP BY has run. That's why only HAVING can use aggregate functions such as SUM(), COUNT() and AVG(). Use

2d ago · 15 min read · mfaysaldev.hashnode.dev  
Read the article

-   [#sql](https://hashnode.com/tag/sql)
-   [#mysql](https://hashnode.com/tag/mysql)
-   [#postgres](https://hashnode.com/tag/postgres)
-   [#beginners](https://hashnode.com/tag/beginners)

## Written by

[Mahir Faysal](https://hashnode.com/@mfaysaldev)

@mfaysaldev

  
[View profile](https://hashnode.com/@mfaysaldev)

Student web developer — PHP, JavaScript, Next.js

I write practical coding tutorials at https://mfaysal.com | Learning cybersecurity on TryHackMe: https://tryhackme.com/p/mfaysal.dev

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
