Difference between Having and Where..

Posted by Muhsinathk under Sql Server on 6/12/2012 | Points: 10 | Views : 1142 | Status : [Member] | Replies : 6
What is the difference between 'Having' and 'Where'?




Responses

Posted by: Muhsinathk on: 6/12/2012 [Member] Bronze | Points: 25

Up
0
Down
Having used with aggregate function.

SELECT state, COUNT(*)
FROM Test
GROUP BY state
HAVING state IN ('CA', 'LA')
ORDER BY state



WHERE clause is used to impose condition on SELECT statement as well as single row function

SELECT cusnum, lstnam, init
FROM Test
WHERE state IN ('CA', 'LA')

Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 6/12/2012 [Member] Silver | Points: 25

Up
0
Down
Answer in one line is : HAVING specifies a search condition for a group or an aggregate function used in SELECT statement.
More details follows,
1.http://blog.sqlauthority.com/2007/07/04/sql-server-definition-comparison-and-difference-between-having-and-where-clause/
2.http://www.sql-tutorial.com/sql-having-sql-tutorial/

Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 6/12/2012 [Member] Bronze | Points: 25

Up
0
Down
Thank youu

Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sriramnandha on: 6/21/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

Having Clause is Group by Function.

Where condition is used apply conditions in sql query.

Regards

Sriram.R

sriram

Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muralidosscm on: 7/4/2012 [Member] Starter | Points: 25

Up
0
Down
http://www.codeproject.com/Articles/25258/Where-Vs-Having-Difference-between-having-and-Wher

Regards
Muralidoss M

Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: perfectchourasia-9163 on: 7/4/2012 [Member] Starter | Points: 25

Up
0
Down
http://sandeep-chourasia.blogspot.in/2011/10/diff-bet-having-and-where-clause.html

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response