SQL / MySQL Intermediate Database · 1 min read

COUNT with GROUP BY

Start the SQL / MySQL learning path »

❮ SQL / MySQL Home All Tutorials ❯

How do I count rows per category?

GROUP BY aggregate.

Example

SQL / MySQL Example
SELECT course, COUNT(*) AS total
FROM enrollments
GROUP BY course
ORDER BY total DESC;

Line-by-Line Walkthrough

Every selected non-aggregate column must appear in GROUP BY.

Need more coins?

You do not have enough coins for this action.

Your balance: 0 coins

Share

Reactions

Loading reactions…