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 a dbrm in db2?
What parameters are used to control the free space in DB2?
What is the function of logging in the db2 database?
Explain about cursor stability?
What is null in db2?
What is the role of data manager in the db2 database?
Mention the downsides of page level lock.
Define check constraint.
What are the 2 sqlcodes that are returned?
What db2 400?
How many databases can be created inside an instance in db2 ?
What are db2 objects?
What is dbrm library?
In an sql table that is embedded, what is the procedure to retrieve rows that are part of a db2 table?
What is consistency token in db2?