Skip to main contentSkip to solution

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

✅ Correct Option: 3

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. COUNT(∗)>5\text{COUNT}(*) > 5), while where filters individual rows before grouping.

Keyboard Shortcuts

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