Which of the following MySQL query is syntactically correct and most preferred…
2023
Which of the following MySQL query is syntactically correct and most preferred one?
- A.
SELECT SECTION, COUNT(*) FROM STUDENT
ORDER BY SECTION
GROUP BY SECTION
WHERE MARKS < 33 AND COUNT(*) > 0;
- B.
SELECT SECTION, COUNT(*) FROM STUDENT
WHERE MARKS < 33
HAVING COUNT(*) > 0
GROUP BY SECTION
ORDER BY SECTION;
- C.
SELECT SECTION, COUNT(*) FROM STUDENT
WHERE MARKS < 33
GROUP BY SECTION
HAVING COUNT(*) > 0
ORDER BY SECTION;
- D.
SELECT SECTION, COUNT(*) FROM STUDENT
GROUP BY SECTION
WHERE MARKS < 33 AND COUNT(*) > 0
ORDER BY SECTION;
Attempted by 1300 students.
Show answer & explanation
Correct answer: C
Correct SQL clause order: SELECT → FROM → WHERE → GROUP BY → HAVING → ORDER BY. Correct query: SELECT SECTION, COUNT(*) FROM STUDENT WHERE MARKS < 33 GROUP BY SECTION HAVING COUNT(*) > 0 ORDER BY SECTION; Why this query is correct: WHERE filters rows before grouping, GROUP BY groups rows by SECTION, HAVING filters groups using the aggregate COUNT(*), and ORDER BY sorts the final result.
A video solution is available for this question — log in and enroll to watch it.