What is the difference between GROUP BY and HAVING clauses?
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:
SQL Server, GROUP BY, database clause, HAVING, www.w3schools.com