Both the HAVING
and WHERE
clauses perform filtering functions. The difference lies in how they perform the operation.
The WHERE
clause performs its operation on single rows and cannot be used with the aggregate functions. On the other hand, the HAVING
clause works on grouped data and that's why it's used with the aggregate functions.
For example, if we wanted to fetch the records having attendance > 80
using a WHERE
clause, we could write this query.
xxxxxxxxxx
SELECT studentname
FROM class
WHERE attendance > 80
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment