Difference between a HAVING CLAUSE and a WHERE CLAUSE

Only with the SELECT statement, we can use HAVING Clause.  Basically HAVING Clause is used with GROUP BY Clause. Without the use of the GROUP BY clause, HAVING behaves like a WHERE clause.

1-   WHERE clause applies to individual rows.

2-  The WHERE clause is applied first to the individual rows in the tables, which means the WHERE clause is fetched data from memory according to condition.

3-  We can use the WHERE clause with the HAVING clause, but it applies before the GROUP BY clause.     
1-   HAVING clause is like a WHERE clause, but applies only to groups as a whole.
2-  The HAVING clause is applied to the rows in the result set, which means the first data is fetched from memory to result set then apply the HAVING clause on the row of the result set.

3-  We can apply a HAVING clause only to columns that also appear in the GROUP BY clause or in an aggregate function

Where Clause Example:

SELECT empName,empDept,empSalary WHERE empSalary=20000

HAVING Clause Example:

SELECT empName,AVG(empSalary)

GROUP BY empName,empSalary HAVING AVG(empSalary)>20000

No comments:

Post a Comment

Please do not enter any spam link in the comment box.

NUnit : Introduction

There are several unit test tools in the market, but one of them is NUnit, the most popular tool for doing unit testing. So in this tutorial...