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
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
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.
Related questions:
2025: 13 May Shift 2
2025: 20 May Shift 1
2025: 13 May Shift 2
2026: 26 May Shift 1