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

When the like statement is used?

0 Answers  


What is the database descriptor?

2 Answers  


How to design maps

1 Answers   Virtusa,


My DB2 program first read the data from a file and then it look into a table with the data it got from the file.If we did not bind the program , should the file read before SQL execution be success??

2 Answers   Xansa,


What are db2 error codes -305 and -407. What is the difference between these 2 error codes ?

1 Answers  






What does CURRENTDATA option in bind indicate

1 Answers   IBM,


What is referential integrity?

5 Answers  


How can you classify the locks in db2?

0 Answers  


What is the syntax for FETCH in DB2 ?

0 Answers   MCN Solutions,


What is an alias?

3 Answers  


if there is a table with huge number of records and if i want to extract only first 3 records from the table, what query i have to provide to retreive first 3 records

4 Answers   UST,


What is tablespace?

3 Answers  


Categories