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.
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.
Prabhu RajaPosted Nov 22, 2011, 12:11 AM
Simply 'Where' clause is used to restrict rows but 'having' clause is used to restrict groups.
Datta KharadPosted Nov 25, 2011, 7:21 AM
If your query resolved then mark as Correct answer.
Vikas MishraPosted Nov 23, 2011, 12:21 PM
Datta KharadPosted Nov 22, 2011, 12:55 AM
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
Pravin MorePosted Nov 21, 2011, 11:49 PM
Click Here to follow discussion on same quetion.
Thanks,
Pravin.
Satyapriya NayakPosted Nov 21, 2011, 9:29 PM
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