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?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| 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. |
| |||
| 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. |
![]() |
| Thread Tools | |
| Display Modes | |
| |
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 |