skip to today's puzzle
SQL Sip

GROUP BY counts each group separately

COUNT on its own gives one number for the whole table. GROUP BY collects the rows into groups first — one group per class, per city — and then counts each group on its own. You get one row per group. Every column you select is either the column you grouped by or a value worked out for the group.

A tiny example

In plain English: For each class, tell me how many students are in it.

SELECT class_id, COUNT(*)
FROM students
GROUP BY class_id;

What comes back

class_idCOUNT(*)
14
29
37

The students split into three classes, and each row is one class with its own headcount.

Related SQL lessons

Ready for a break?

Take on today's cozy puzzle. A fresh, bite-sized query waits every morning — no timers, no pressure.

play today's sip