Interview Question

What is GROUP BY?

GROUP BY creates groups for aggregate calculations.

💡 Concept ✅ Quick Revision 🗃️ SQL

Answer

GROUP BY combines rows that have equal grouping values into groups. • Aggregate functions can calculate one result per group. • Selected non-aggregate expressions generally must be grouping expressions. • Grouping happens after WHERE filtering.

💡 SQL Example

SELECT department_id, COUNT(*) FROM employees GROUP BY department_id;

Result

10 | 4 20 | 3

⚡ Quick Revision

GROUP BY creates groups for aggregate calculations.