Skip to main contentSkip to solution

To display the 'Number of Bikes' purchased by each customer from the 'SALE' table, what will be the correct order of the following statements?

(A) SELECT CustID, COUNT(*) "Number of Bikes"

(B) HAVING COUNT(*)>3

(C) GROUP BY CustID

(D) FROM SALE

Solution

✅ Correct Option: 3

SQL clauses must follow a fixed order: SELECT, FROM, GROUP BY, HAVING. HAVING filters the groups made by GROUP BY, so it comes last.

(A) SELECT CustID, COUNT(*) "Number of Bikes"

(D) FROM SALE

(C) GROUP BY CustID

(B) HAVING COUNT(*)>3


Options 1, 2 and 4: each puts a clause out of order (HAVING before FROM or GROUP BY, or GROUP BY before FROM), which is a syntax error.

Memory trick: the order is 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