Count child rows per parent.
Section: joins
Join and aggregate child rows
sql
sql
SELECT u.id, u.email, COUNT(o.id) AS order_count
FROM users u
LEFT JOIN orders o ON o.user_id = u.id
GROUP BY u.id, u.email;Explanation
A classic reporting query for dashboards and admin pages.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing joins
Left join to keep unmatched parent rows
Return all rows from the left table and matching rows from the right table.