GROUP BY Clause (SQL Only)

See AlsovbhowSQLGROUPBYSee                 ExamplevbhowSQLGROUPBYEx>Low

Description

GROUP BY combines records with identical values in the specified field list into a single record.  A summary value is created for each record if you include an aggregate function, such as Sum or Count, in the SELECT statement.  If the SQL statement includes a WHERE clause, records are grouped after applying the WHERE conditions to the records.

Notes

         GROUP BY is optional but when included follows FROM and WHERE.

         Summary values are omitted if there is no aggregate function in the SELECT statement.

         Null values in GROUP BY fields are grouped and are not omitted.  However, Null values aren't evaluated in any aggregate function.

         Use the WHERE clause to exclude rows you don't want grouped.

         A field in the GROUP BY field list can refer to any field listed in the FROM clause, even if the field is not included in the SELECT statement, provided the SELECT statement includes at least one aggregate function.

         All fields must be in the GROUP BY field list or must be referred to by an aggregate function in the SELECT statement.

         When you type a field name that contains a space or punctuation, surround the name with brackets:

  SELECT [Product Name], Sum([Units in Stock])
  FROM Products
  GROUP BY [Product Name]