IT Community - Software Programming, Web Development and Technical Support

What is the difference between a HAVING CLAUSE and a WHERE CLAUSE in SQL Server?

This is a discussion on What is the difference between a HAVING CLAUSE and a WHERE CLAUSE in SQL Server? within the Database Support forums, part of the Web Development category; What is the difference between a HAVING CLAUSE and a WHERE CLAUSE in SQL Server?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Database Support

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-23-2007, 06:06 AM
mobilegeek mobilegeek is offline
D-Web Analyst
 
Join Date: Jun 2007
Posts: 205
mobilegeek is on a distinguished road
Question What is the difference between a HAVING CLAUSE and a WHERE CLAUSE in SQL Server?

What is the difference between a HAVING CLAUSE and a WHERE CLAUSE in SQL Server?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-23-2007, 06:06 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: What is the difference between a HAVING CLAUSE and a WHERE CLAUSE in SQL Server?

You can use Having Clause with the GROUP BY function in a query and Where Clause is applied to each row before they are part of the GROUP BY function in a query.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-07-2007, 08:04 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Default Re: What is the difference between a HAVING CLAUSE and a WHERE CLAUSE in SQL Server?

Having clause is usually used with Group By clause although it can be used without it too. Having is just an additional filter to Where clause.

Where clause applies to the individual rows whereas Having clause is used to test some condition on the group(usually aggregate methods) rather than on individual rows.

Example of HAVING and WHERE in one query:

SELECT titles.pub_id, AVG(titles.price)
FROM titles INNER JOIN publishers
ON titles.pub_id = publishers.pub_id
WHERE publishers.state = 'CA'
GROUP BY titles.pub_id
HAVING AVG(titles.price) > 10
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!

Last edited by S.Vinothkumar : 08-08-2007 at 12:23 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the length(picture clause)? S.Vinothkumar Database Support 1 10-30-2007 01:17 AM
finally clause of a try-catch-finally statement vigneshgets Java Programming 2 08-16-2007 07:35 AM
In the WHERE clause what is BETWEEN and IN? bluesky Database Support 2 08-07-2007 05:24 AM
What is the difference between UNION and UNIONALL in SQL Server? bluesky Database Support 1 07-25-2007 05:53 AM
If I return out of a try/finally in C#, does the code in the finally-clause run? H2o C# Programming 1 07-22-2007 11:27 PM


All times are GMT -7. The time now is 07:03 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0