what is the difference between where clause and having clause

Answer Posted / sriram

WHERE clause is used to impose condition on SELECT
statement as well as single row function and is used before
GROUP BY clause where as HAVING clause is used to impose
condition on GROUP Function and is used after GROUP BY
clause in the query

WHERE applies to rows HAVING applies to summarized rows
(summarized with GROUP BY) if you wanted to find the
average salary in each department GREATER than 333 you
would code:

SELECT DEPARTMENT AVG(SALARY)

FROM EMP

WHERE DEPARTMENT > 333

GROUP BY DEPARTMENT

IF you then wanted to filter the intermediate result to
contain departments where the average salary was greater
that 50 000 you would code:

SELECT DEPARTMENT AVG(SALARY)

FROM EMP

WHERE DEPARTMENT > 333

GROUP BY DEPARTMENT

HAVING AVG(SALARY) > 50000.

Where executes first

GROUP BY next

and finally HAVING


Is This Answer Correct ?    9 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between drop table and delete table?

541


What do you mean by cursor?

578


In an sql table that is embedded, what is the procedure to retrieve rows that are part of a db2 table?

631


What db2 400?

671


What is universal database?

607






What are catalog tables in db2?

601


What is buffer pool in the db2 database?

610


How does a cursor work?

553


How to test SQL -911 error while developing COB-DB2 program

6699


Define buffer pool.

616


How can deadlocks be resolved?

531


Which command is used to connect to a database in DB2 ? Give the Syntax.

592


What is database alias db2?

593


What is the physical storage length of date data type?

720


How would the varchar column remarks defined?

626