What is difference between WHERE and HAVING in SQL Server?
Dung Do Tien
Oct 19 2020
270
I only use WHERE
clause to filter data but HAVING
also use to filter data. Can anybody explain to me what is the difference between them? and when we should use them?
Have 1 answer(s) found.
-
M0
Marry Christ Oct 19 2020
I can note some difference between them as below:
1. WHERE
- Filter data from a result, usually filter columns available in the table.
- It filters before any groups are made.
- Can't use the aggregate function to filter.
2. HAVING
- Used to filter values from a group.
- Only use the aggregate function to filter.
- Can't using
HAVING
if not use to theGROUP BY
clause.- Performance is SLOW because the aggregate function needs to calculation.
* Type maximum 2000 characters.
* All comments have to wait approved before display.
* Please polite comment and respect questions and answers of others.