Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Collapse the table of content
Expand the table of content
Expand Minimize

GROUP BY Clause (SQL Server Compact)

Specifies the groups (equivalence classes) that output rows are to be placed in. If aggregate functions are included in the SELECT clause <select list>, the GROUP BY clause calculates a summary value for each group.

[ GROUP BY group_by_expression [ ,...n ] ] 


An expression that grouping is performed on. The group_by_expression argument is also known as a grouping column. For more information, see Remarks.

The group_by_expression parameter can be a column or a nonaggregate expression that references a column. A column alias that is defined in the select list cannot be used to specify a grouping column. Aggregate expressions cannot be specified in a group_by_expression.

Note Note

Columns of type ntext and image cannot be used in group_by_expression.

When GROUP BY is specified, the GROUP BY expression must exactly match the select list expression, or each column in any nonaggregate expression in the select list must be included in the GROUP BY list.

Note Note

GROUP BY ALL is not supported in SQL Server Compact.

The following example returns a list of all orders grouped by product ID.

SELECT [Product ID], COUNT(*) AS Expr1 FROM [Order Details] GROUP BY [Product ID]
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft