# What is the difference between WHERE and HAVING clauses in SOQL?

**Topic:** Soql · **Difficulty:** Easy · **Asked at:** Infosys, Wipro, Mindtree · **Tags:** soql, aggregate, group-by

Read it on the site: https://www.forcechallenges.com/interview-questions/what-is-the-difference-between-where-and-having-clauses-in-soql

## Answer

`WHERE` filters **individual rows** before grouping and cannot use aggregate functions. `HAVING` filters **groups** after `GROUP BY` and works with aggregate functions.

```soql
SELECT AccountId, COUNT(Id) FROM Contact
WHERE Email != null
GROUP BY AccountId
HAVING COUNT(Id) > 5
```

---
Source: ForceChallenges · last updated 2026-10-21
