question

OracleApprender avatar image
OracleApprender asked

What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?

Can anybody explain to me the differences between Having and Where clauses ? And also can we use both within the same query ? Please give an example if possible. Thank you.

queryoracledatabaseparallel-clause
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

goyuix avatar image
goyuix answered

While they accomplish a very similar function, their uses are entirely different:

First, a HAVING clause is only allowed / makes sense with a GROUP BY - which would typically imply you are using an aggregate of some sort in your SELECT statement. This also stems from the fact that in many cases aggregate functions are not allowed in the WHERE expression.

Second, the following is the order in which key expressions of your statement are executed:

  • FROM clause
  • WHERE clause
  • GROUP BY clause
  • HAVING clause
  • SELECT clause
  • ORDER BY clause

Allowing the data to first be refined by the FROM and the WHERE expressions allows for certain performance improvements when using the HAVING clause on a (potentially) smaller data set.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jatin avatar image
jatin answered

this is very good explanation, for easy and better explanation you can visit this link http://dotnetpeoples.blogspot.com/2011/04/having-clause-vs-where-clause.html

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.