GROUP BY

The clause that splits rows into groups sharing the same values, so aggregates return one result per group.

In more detail

Every selected column that is not inside an aggregate must be in the GROUP BY. Several columns form one combined group key, such as month and status. GROUP BY does not guarantee any order, so add ORDER BY.

Example

SELECT status, COUNT(*) AS orders FROM orders GROUP BY status;

Related terms

Taught in

References

Certification courses