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
What is the difference between using bind () and rebind () methods of naming class?
What is the use of db2?
Is the primary key a clustered index?
How to compare data between two tables in db2?
On which levels locks can be applied?
What is a storage group (stogroup)?
define clustering index.
can we view the access paths created by dbrm ? how ? thx
What is load replace in db2?
Describe major components of db2?
What are db2 objects?
What is ibm db2 connect?
Explain correlated sub-queries.
What is the maximum size of a char data type in db2?
Why do we need reorg in db2?