Skip to main contentSkip to solution

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.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question