Skip to content
CodeKruPro

Which columns may appear next to GROUP BY?

QuizMedium

Why do PostgreSQL and MySQL (with its default settings) reject this query?

SELECT dept_id, name, COUNT(*)
FROM employees
GROUP BY dept_id;
  • name is neither in GROUP BY nor inside an aggregate, so a group of several employees has no single name to show
  • COUNT(*) cannot be used with GROUP BY
  • GROUP BY needs every column of the table
  • dept_id must not be selected when it is grouped

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in