______ 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
______ 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
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.
Related questions:
2025: 16 May Shift 1
2026: 23 May Shift 1
2026: 18 May Shift 2