what is the difference between 'having' and 'where' clause ?
what is difference between 'having and 'where' clause?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Abhay ShankerPosted Dec 10, 2013, 3:19 AM
WHERE CLAUSE
Using where clause we can restrict or filter the records that we get from select statement.
SELECT *
FROM emp
WHERE deptno = 10;
Having Clause:
Having clause is used to restrict the records that are grouped using group by clause.
SELECT deptno,job,SUM(sal) tsal
FROM emp
GROUP BY deptno,job
HAVING SUM(sal) > 3000;
AartiPosted Dec 10, 2013, 12:29 AM
having is used as a conditions on the aggregate results from the group by ...
Example:
SELECT column_name, aggregate_function(column_name)FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value
Here, WHERE column_name operator value says
"Return results for table_name where 'column_name operator value' is true".
Only after all the results from these conditions are found, it groups by column_name.
Then HAVING aggregate_function(column_name) operator value says "For the resulting aggregate groups, run 'aggregate_function(column_name)' and return only results where 'aggregate_function(column_name) operator value' is true."
Hope this will clear you.
Satyapriya NayakPosted Nov 21, 2013, 4:30 AM
HanookPosted Nov 21, 2013, 12:25 AM
Jignesh TrivediPosted Nov 20, 2013, 11:15 PM
Where Clause use to apply condition on individual rows. Having clause used to apply condition on aggregation means count average, min max, sum etc..
WHERE use before GROUP BY and HAVING after GROUP BY
Please refer
http://www.programmerinterview.com/index.php/database-sql/having-vs-where-clause/
http://www.codeproject.com/Articles/25258/Where-Vs-Having-Difference-between-having-and-Wher
hope this will help you
VulpesPosted Nov 20, 2013, 1:54 PM
Aggregate functions include AVG, COUNT, FIRST, LAST, MAX, MIN and SUM.