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?

Answer: C. SELECT SECTION, COUNT(*) FROM STUDENT WHERE MARKS < 33 GROUP BY SECTION HAVING COUNT(*) > 0 ORDER BY SECTION;Correct SQL clause order: SELECT → FROM → WHERE → GROUP BY → HAVING → ORDER BY. Correct query: SELECT SECTION, COUNT(*) FROM STUDENT WHERE MARKS < 33 GROUP BY…

  1. A.

    SELECT SECTION, COUNT(*) FROM STUDENT

    ORDER BY SECTION

    GROUP BY SECTION

    WHERE MARKS < 33 AND COUNT(*) > 0;

  2. B.

    SELECT SECTION, COUNT(*) FROM STUDENT

    WHERE MARKS < 33

    HAVING COUNT(*) > 0

    GROUP BY SECTION

    ORDER BY SECTION;

  3. C.

    SELECT SECTION, COUNT(*) FROM STUDENT

    WHERE MARKS < 33

    GROUP BY SECTION

    HAVING COUNT(*) > 0

    ORDER BY SECTION;

  4. D.

    SELECT SECTION, COUNT(*) FROM STUDENT

    GROUP BY SECTION

    WHERE MARKS < 33 AND COUNT(*) > 0

    ORDER BY SECTION;

Attempted by 1613 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.

Explore the full course: Rssb Basic Computer Instructor

Loading lesson…