July 15, 2024

Difference between WHERE and HAVING Clause

WHERE and HAVING are SQL clauses used for searching purposes. Both are almost same, but have some difference that may arise confusion. This article describes what is the difference between the WHERE and HAVING clause?

Both WHERE & HAVING specifies a search condition used in SELECT statement. WHERE clause applies to individual rows.

HAVING clause applies only to groups as a whole.

A query can contain both a WHERE clause and a HAVING clause. The WHERE clause is applied first to the individual rows in the tables. The HAVING clause is then applied and make group with the rows that meet the conditions in the WHERE clause. Only the groups that meet the HAVING conditions appear in the query output.

HAVING clause is used for a group or an aggregate function used in SELECT statement.

That’s all about where and having.

Rashedul Alam

I am a software engineer/architect, technology enthusiast, technology coach, blogger, travel photographer. I like to share my knowledge and technical stuff with others.

View all posts by Rashedul Alam →

Leave a Reply

Your email address will not be published. Required fields are marked *