Skip to main contentSkip to solution

What will be the sequence of the given SQL clauses to display the Customer Id (CustID) and number of cars purchased if the customer purchased more than 1 car from SALE table?

A. GROUP BY CustID

B. COUNT(*)

C. HAVING COUNT (*)>1

D. FROM SALE

E. SELECT CustID

Solution

✅ Correct Option: 4

SQL clauses must follow the fixed order SELECT, FROM, GROUP BY, HAVING. COUNT(*) is not a separate clause. It is part of the SELECT list, so it comes right after CustID.

E. SELECT CustID

B. COUNT(*)

D. FROM SALE

A. GROUP BY CustID

C. HAVING COUNT(*)>1

The full query is: SELECT CustID, COUNT() FROM SALE GROUP BY CustID HAVING COUNT()>1;


Options 1, 2 and 3: GROUP BY or COUNT(*) is placed before FROM, which is invalid because FROM must come before GROUP BY and HAVING.

HAVING filters groups after GROUP BY, so it always comes last here. WHERE would filter rows before grouping and cannot use COUNT(*).

Keyboard Shortcuts

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