thinQmaster Virtual testing partner Adaptive practice exams that find your weak spots and drill them. Every answer explained. From $69
Enroll

thinQmaster

Find your exam

Five questions free, before you decide.

Step 1 · choose a vendor

In one of our camps? Your practice exams come with the tuition — they are on your study page already.

Data & Analytics · Foundational

GROUP BY Clause

The clause that groups rows sharing the same values so that aggregate functions return one row per group.

Definition

Every non-aggregated column in the SELECT list must appear in GROUP BY in standard SQL. Extensions such as ROLLUP, CUBE and GROUPING SETS add subtotal and grand-total rows.

Example

SELECT Region, Product, SUM(Sales) FROM Sales GROUP BY Region, Product;

Exam tip

A 'column is not contained in an aggregate function or the GROUP BY clause' error means a selected column is missing from GROUP BY.

Related terms