When you group and summarize SQL results, you use the GROUP BY Clause to output a row across specified column values. It is typically used in conjunction with aggregate functions such as SUM or Count to summarize values. In SQL, groups are unique combinations of fields. Rather than returning every row in a table, when values are grouped, only the unique combinations are returned.
If you want to start to learn about grouping data, I would recommend first reading this article: How to Use GROUP BY to Summarize Query Results
Once you understand how to group and summarize data, I would recommend reading the following:
- What is the Difference between ORDER and GROUP BY?
- What is the difference between WHERE and HAVING clauses?
These article will help you understand the subtle, yet important differences between these commands.
All the examples for this lesson are based on Microsoft SQL Server Management Studio and the sample databases AdventureWorks and WideWorldImporters. You can get started using these free tools using my guide Getting Started Using SQL Server