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 drop table and delete table?
What do you mean by cursor?
In an sql table that is embedded, what is the procedure to retrieve rows that are part of a db2 table?
What db2 400?
What is universal database?
What are catalog tables in db2?
What is buffer pool in the db2 database?
How does a cursor work?
How to test SQL -911 error while developing COB-DB2 program
Define buffer pool.
How can deadlocks be resolved?
Which command is used to connect to a database in DB2 ? Give the Syntax.
What is database alias db2?
What is the physical storage length of date data type?
How would the varchar column remarks defined?