Practice free →
HomeGATE CSEcomputerscienceDatabase Management Systems › Why is `SELECT branch, name, AVG(salary) FROM em…

Why is `SELECT branch, name, AVG(salary) FROM employees GROUP BY branch` illegal in standard SQL?

AAVG cannot be used with GROUP BY
B`name` is non-aggregated but not in GROUP BY
Cbranch and name conflict in the WHERE clause
Dthe query is missing a HAVING clause
Answer & Solution
Correct answer: B. `name` is non-aggregated but not in GROUP BY
Each branch has many employees, so each group has many names. SQL requires that every non-aggregated SELECT column appear in GROUP BY, so there is one value per group to display. Either add `name` to GROUP BY (changing the grouping), wrap it in an aggregate like MAX(name), or remove it from SELECT.
Solve this in the app — GATE CSE practice & 24k+ MCQs →
Related questions