Skip to main contentSkip to solution

______ paymentmode, COUNT(paymentmode) FROM SALETABLE _______ paymentmode _________ COUNT(*)>1 ________ paymentmode;

Arrange the words given below to be filled in the blanks in the correct order in the above query.

(A) HAVING

(B) GROUP BY

(C) SELECT

(D) ORDER BY

Solution

✅ Correct Option: 1

SQL clauses must appear in a fixed order: SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY. HAVING filters the groups that GROUP BY creates, so it must come after GROUP BY.

(C) SELECT

(B) GROUP BY

(A) HAVING

(D) ORDER BY

The full query reads: SELECT paymentmode, COUNT(paymentmode) FROM SALETABLE GROUP BY paymentmode HAVING COUNT(*)>1 ORDER BY paymentmode;


Options 2 and 3: HAVING cannot come before GROUP BY, because it works on grouped results.

Option 4: ORDER BY is always the last clause, so it cannot come before HAVING.

WHERE filters rows before grouping, while HAVING filters groups after grouping.

Keyboard Shortcuts

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