SQL

GROUP BY Statement

Learn how to group rows that have the same values.

By TechCoder TeamLast updated: 2026-06-02
In a Nutshell

Learn how to group rows that have the same values. This hands-on tutorial focuses on practical implementation of group by statement concepts.

Grouping Data

The GROUP BY statement groups rows that have the same values into summary rows, like "find the number of customers in each country".

It is often used with aggregate functions (COUNT, MAX, MIN, SUM, AVG).

Syntax

SELECT column_name(s)
FROM table_name
GROUP BY column_name(s);

Example: Customers by Country

Count the number of customers in each country.

SQL PLAYGROUND
⏳ Loading editor…

Sorting Groups

You can order the results after grouping.

SQL PLAYGROUND
⏳ Loading editor…