Skip to main content

How do you group data by a single field?

To group data by a single field, use the GROUP BY operator with that field's name.

Example

sql
SELECT department, COUNT(*) FROM employees GROUP BY department;

Here:

  • GROUP BY department creates groups by department name,
  • COUNT(*) counts employees in each department.

In the result, each output row is one group sharing a common department value plus its computed aggregate.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.