I want to know what is the difference between a HAVING CLAUSE and WHERE CLAUSE in SQL server.
Thank you.
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
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jul 27, 2012, 11:39 PM EDT
Hardik PatelRank #4,439 · 343 reputationPosted Jul 27, 2012, 11:49 PM EDT
1) where clause specifes the criteria which individual record must meet to be selected by query. it can be used without GROUP BY Clause. the HAVING Clause can not be used without GROUP BY Clause .
2) where clause can not contain aggregate function. Havng clause can contain aggregate function.
Vilas GiteRank #951 · 2.1K reputationPosted Jul 28, 2012, 12:22 AM EDT
Just Watch & Implement queries.
http://www.youtube.com/watch?v=0EgAxYv-44o
http://www.w3schools.com/sql/sql_having.asp
http://www.w3schools.com/sql/sql_groupby.asp
Thanks..:)
Satyapriya NayakRank #47 · 31.5K reputationPosted Jul 29, 2012, 10:44 AM EDT
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.
Thanks
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 29, 2012, 7:32 PM EDT
Hi,
both, WHERE and HAVING clauses allow us to restrict the data you're selecting by establishing conditions.
Use HAVING instead of WHERE when you want to establish a condition that involves a grouping (aggregating) function like count(), max(), sum(), etc.
The WHERE clause is applied first to the individual rows in the tables
Please refer
http://www.codeproject.com/Articles/25258/Where-Vs-Having-Difference-between-having-and-Wher
http://blog.sqlauthority.com/2007/07/04/sql-server-definition-comparison-and-difference-between-having-and-where-clause/
http://www.techonthenet.com/sql/having.php
hopr this will help you.