Select Statement  «Prev 

An example of the GROUP BY clause

Null or blank values can be returned as part of your GROUP BY query's result set. These occur when the values used by the GROUP BY clause include blank values in the database table. If you group by state, for example, and you have blank values for one of the states, you will receive one of your GROUP BY classes as a blank, or null, value. These are not errors in the query, they are just indications that you have values missing from a column you have indicated in the GROUP BY clause.
This section examines the GROUP BY clause, which is used in conjunction with the SELECT statement. It allows you to group identical data into one subset rather than listing each record. The GROUP BY clause is at its most powerful when used with summarizing and aggregating functions of SQL, which are covered in the next section. The GROUP BY clause is also very useful with subqueries. The aim of this module is to get a handle on how GROUP BY works; the next section shows you how to use it more effectively

The GROUP BY clause can be used in a SELECT statement to collect data across multiple records and group the results by one or more columns. The syntax for the GROUP BY clause is:

SELECT column1,  ... , column_n, aggregate_function (expression)
FROM tables
WHERE predicates
GROUP BY column1, column2, ... , column_n;