Search⌘ K
AI Features

Uses of the GROUP BY Function

Understand how to group data rows using the GROUP BY statement in T-SQL. Explore using aggregate functions like COUNT, SUM, and AVG to summarize grouped data. Learn to filter rows before grouping with WHERE and groups after grouping with HAVING to refine query results.

When retrieving data from the database, we can group rows using the GROUP BY statement.

Basic use of GROUP BY

The GROUP BY function is used as part of a SELECT statement:

SELECT ColumnName FROM TableSchema.TableName
GROUP BY ColumnName;

In this basic form, GROUP BY allows us to see the distinct values in a given column. In some cases, this approach is much more effective in terms of performance compared to the ...