Skip to main contentSkip to solution

Arrange the following SQL Command in correct order of writing the query:

(A) SELECT PaymentMode, Count(PaymentMode)

(B) GROUP BY Paymentmode HAVING COUNT(*)>1

(C) ORDER BY Paymentmode;

(D) FROM SALE

Solution

✅ Correct Option: 1

SQL clauses must be written in a fixed order: SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY. Here that gives SELECT (A), FROM (D), GROUP BY ... HAVING (B), ORDER BY (C).

(A) SELECT PaymentMode, Count(PaymentMode)

(D) FROM SALE

(B) GROUP BY Paymentmode HAVING COUNT(*)>1

(C) ORDER BY Paymentmode;


Options 2 and 4: ORDER BY cannot come before GROUP BY or FROM; it is always the last clause.

Option 3: GROUP BY cannot come before FROM, because the table must be named first.

Memory trick: "Some Friends Will Get Hurt Often" gives SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY.

Keyboard Shortcuts

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