What is the difference between GROUP BY and HAVING clauses?

Filed under: I'm a Newbie, Programming, Transact-SQL (T-SQL) — Bryan Oliver at 4:32 pm on Tuesday, August 28, 2007

Q:  What is the difference between GROUP BY and HAVING clauses?

Bryan Oliver says:  The GROUP BY and HAVING clauses are used together. The HAVING clause is used as a final filter (rather than as a conditional filter) on the aggregate column values in the result set of a SELECT statement. In other words, the query has to be grouped before the HAVING clause can be applied. For example, consider the following statement, which displays the count of students in various classes (classes of students = 1, 2, 3, 4, corresponding to freshman, sophomore, and so on). For an excellent overview of these clauses, check out the online reference at w3schools.com.

Technorati Tags:
, , , ,

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>