Question 24Asked in UGC NET Computer Science, August 2016 (Paper II & III, Selected Questions)

Consider a database table R with attributes A and B. Which of the following SQL queries is illegal?

  1. ASELECT A FROM R;
  2. BSELECT A, COUNT (*) FROM R;
  3. CSELECT A, COUNT(*) FROM GROUP BY A;
  4. DSELECT A, B, COUNT (*) FROM R GROUP BY A, B;
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.

From UGC NET Computer Science PYQ, August 2016 (Paper II & III, Selected Questions)

This is question 24 of UGC NET Computer Science PYQ, August 2016 (Paper II & III, Selected Questions). See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.