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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Nov 20, 2013, 8:54 AM EST
Aggregate functions include AVG, COUNT, FIRST, LAST, MAX, MIN and SUM.
Jignesh TrivediRank #16 · 50.3K reputationPosted Nov 20, 2013, 6:15 PM EST
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
Hanook159 reputationPosted Nov 20, 2013, 7:25 PM EST
Satyapriya NayakRank #47 · 31.5K reputationPosted Nov 20, 2013, 11:30 PM EST
AartiRank #2,383 · 594 reputationPosted Dec 9, 2013, 7:29 PM EST
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.
Abhay ShankerRank #375 · 6.7K reputationPosted Dec 9, 2013, 10:19 PM EST
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;