Question 70

Which of the following MySQL query is syntactically correct and most preferred one?

  1. ASELECT SECTION, COUNT(*) FROM STUDENT ORDER BY SECTION GROUP BY SECTION WHERE MARKS<33 AND COUNT(*)>0;
  2. BSELECT SECTION, COUNT(*) FROM STUDENT WHERE MARKS<33 HAVING COUNT(*)>0 GROUP BY SECTION ORDER BY SECTION;
  3. CSELECT SECTION, COUNT(*) FROM STUDENT WHERE MARKS<33 GROUP BY SECTION HAVING COUNT(*)>0 ORDER BY SECTION;
  4. DSELECT SECTION COUNT(*) FROM STUDENT GROUP BY SECTION WHERE MARKS<33 AND COUNT(*)>0 ORDER BY SECTION;
Show answerHide answer

Correct answer: (C) SELECT SECTION, COUNT(*) FROM STUDENT WHERE MARKS<33 GROUP BY SECTION HAVING COUNT(*)>0 ORDER BY SECTION;

Explanation

The clauses must come in the order WHERE, GROUP BY, HAVING, ORDER BY. Conditions on groups such as COUNT(*) > 0 go in HAVING, not WHERE.

From DSSSB TGT Computer Science Practice Set 5

This is question 70 of DSSSB TGT Computer Science Practice Set 5. 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.