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
How can you quickly find out the # of rows updated after an update statement?
What is cobol db2?
What is db2?
what is diffrence b/w file-aid tool and file-aid utility???
What are the contents of a dclmgen?
What does sqlcabc has?
How to check table size in db2 sap?
What is the difference between plan and package in db2?
What parameters are used to control the free space in DB2?
Mention data types used in db2 ?
What is a bind card?
What is cloudant database?
What is a bind in db2?
What is the reason behind not using select * in embedded sql programs?
What is the syntax for seeing the columns and data types of a table in the db2 database?