Consider a database table R with attributes A and B. Which of the following SQL queries is illegal?
Show answerHide answer
Correct answer: (B) SELECT A, COUNT (*) FROM R;
Explanation
SELECT A, COUNT(*) FROM R; is illegal: when an aggregate function (SUM, AVG, COUNT, MAX, MIN) is used in the SELECT clause along with a non-aggregated attribute, a GROUP BY clause on that attribute is required. SELECT A, B, COUNT(*) FROM R GROUP BY A, B; is legal.