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 a dbrm in db2?

576


What parameters are used to control the free space in DB2?

642


What is the function of logging in the db2 database?

645


Explain about cursor stability?

623


What is null in db2?

575






What is the role of data manager in the db2 database?

649


Mention the downsides of page level lock.

711


Define check constraint.

644


What are the 2 sqlcodes that are returned?

643


What db2 400?

679


How many databases can be created inside an instance in db2 ?

602


What are db2 objects?

641


What is dbrm library?

578


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

644


What is consistency token in db2?

641