Hi friends..........
What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?
Thanks............
Loading
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
Prabhu RajaRank #861 · 2.6K reputationPosted Nov 21, 2011, 7:11 PM EST
Simply 'Where' clause is used to restrict rows but 'having' clause is used to restrict groups.
Satyapriya NayakRank #47 · 31.5K reputationPosted Nov 21, 2011, 4:29 PM EST
HAVING clause: -Specifies a search condition for a group or an aggregate. HAVING can be used only with the SELECT statement. HAVING is typically used in a GROUP BY clause. When GROUP BY is not used, HAVING behaves like a WHERE clause. Having Clause is basically used only with the GROUP BY function in a query.
WHERE Clause:- is applied to each row before they are part of the GROUP BY function in a query.Also refer the thread below
http://www.c-sharpcorner.com/Forums/Thread/143804/having-and-where-clause.aspx
Thanks
Pravin MoreRank #1,419 · 1.2K reputationPosted Nov 21, 2011, 6:49 PM EST
Click Here to follow discussion on same quetion.
Thanks,
Pravin.
Datta KharadRank #2,135 · 668 reputationPosted Nov 21, 2011, 7:55 PM EST
The SQL HAVING keyword provides a search condition for a group or aggregate. The SQL HAVING clause works together with the SQL SELECT clause. The SQL HAVING clause is somewhat similar to the SQL WHERE clause, because it specifies a search condition.
There is one important difference between SQL HAVING and SQL WHERE clauses. The SQL WHERE clause condition is tested against each and every row of data, while the SQL HAVING clause condition is tested against the groups and/or aggregates specified in the SQL GROUP BY clause and/or the SQL SELECT column list.
It is important to understand that if a SQL statement contains both SQL WHERE and SQL HAVING clauses the SQL WHERE clause is applied first, and the SQL HAVING clause is applied later to the groups and/or aggregates.
Example:-
SELECT City, AVG(AverageTemperature)
FROM Weather
GROUP BY City
HAVING AVG(AverageTemperature) > 19
Vikas MishraRank #559 · 4.3K reputationPosted Nov 23, 2011, 7:21 AM EST
Datta KharadRank #2,135 · 668 reputationPosted Nov 25, 2011, 2:21 AM EST
If your query resolved then mark as Correct answer.