Arrange the following statements in correct order.
(A) HAVING CLAUSE
(B) FROM TABLENAME
(C) GROUP BY
(D) SELECT (AGGREGATE FUNCTION)
Arrange the following statements in correct order.
(A) HAVING CLAUSE
(B) FROM TABLENAME
(C) GROUP BY
(D) SELECT (AGGREGATE FUNCTION)
Solution
✅ Correct Option: 3
SQL clauses are written in a fixed order: SELECT, then FROM, then GROUP BY, then HAVING.
(D) SELECT (AGGREGATE FUNCTION)
(B) FROM TABLENAME
(C) GROUP BY
(A) HAVING CLAUSE
HAVING filters the groups formed by GROUP BY, so it must come after GROUP BY. A WHERE clause, if used, goes between FROM and GROUP BY because it filters rows before grouping.
Option 4: puts HAVING before GROUP BY, but HAVING can only filter groups that already exist.
Related questions:
2025: 30 May Shift 2
2026: 29 May Shift 2
2026: 26 May Shift 1
2026: 13 May Shift 2