Select the correct order of the following while writing a query for grouping of records in SQL.
(A) group by
(B) having
(C) from
(D) select
Select the correct order of the following while writing a query for grouping of records in SQL.
(A) group by
(B) having
(C) from
(D) select
Solution
The clauses of a grouping query are written in the order select, from, group by, having.
(D) select: chooses the columns or aggregates to display
(C) from: names the table
(A) group by: groups the rows
(B) having: filters the groups, so it must come after group by
Option 1: places having before group by, but having filters groups that group by has already formed.
Having is used for conditions on aggregates (e.g. ), while where filters individual rows before grouping.
Related questions:
2026: 23 May Shift 2
2026: 21 May Shift 1
2025: 3 June Shift 2
2026: 18 May Shift 2
2025: 14 May Shift 1