Place the following clauses in correct order to write a query in SQL.
(A) SELECT FROM
(B) HAVING
(C) ORDER BY
(D) GROUP BY
Place the following clauses in correct order to write a query in SQL.
(A) SELECT FROM
(B) HAVING
(C) ORDER BY
(D) GROUP BY
Solution
✅ Correct Option: 1
(A) SELECT ... FROM: chooses the columns and the table
(D) GROUP BY: groups the selected rows
(B) HAVING: filters the groups formed by GROUP BY
(C) ORDER BY: sorts the final result, so it always comes last
Option 2: HAVING cannot come before GROUP BY, because it filters groups that GROUP BY creates.
Options 3 and 4: ORDER BY cannot come before GROUP BY or HAVING, because it is always the last clause.
Related questions:
2026: 21 May Shift 1
2025: 21 May Shift 1
2025: 21 May Shift 1