what is the difference between where clause and having clause

Answers were Sorted based on User's Feedback



what is the difference between where clause and having clause..

Answer / 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

what is the difference between where clause and having clause..

Answer / selvam a

HAVING clause can only compare a built in function but WHERE
clause can compare column name.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More DB2 Interview Questions

What is an EXPLAIN in DB2. How and what is the steps followed in EXPLAIN command. Can all the queries be used in EXPLAIN command to check the performance.

3 Answers   IBM,


On which levels locks can be applied?

0 Answers  


What is the purpose of the SDSNLOAD dataset in the STEPLIB while running DB2 programs?

2 Answers  


How can deadlocks be resolved?

0 Answers  


What are the 4 environments which can access DB2 ?

2 Answers  






Mention the way of highlighting as well as putting a cursor to use in a cobol program.

0 Answers  


What is the cascade rule and how does it relate to deletions made with a subselect?

1 Answers  


if any of the column names is provided wrong, where do you get the error(during precompilation or during Bind)

3 Answers  


I have 3 cursors declared. Cursor1 retieves some data. Based on this curso2 will also fetches some data. In cursor3 (using for some updation) I'm using the data retrieved by the above 2 cursor. My question is, while working with cursor3, periodically if I give commit, will all the three crsors will be closed or only cursor3 will be closed?

4 Answers  


What is a synonym? How is it used?

2 Answers  


can we view the access paths created by dbrm ? how ? thx

2 Answers   IBM,


How do I create a view in db2?

0 Answers  


Categories