Multiple choice technology databases

In a SELECT statement that includes a WHERE clause, where is teh GROUP BY clause placed in the SELECT statement?

  1. Immediately after the SELECT clause

  2. Before the WHERE clause

  3. Before the FROM clause

  4. After the ORDER BY clause

  5. After the WHERE clause

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

The correct order of SQL clauses is: SELECT → FROM → WHERE → GROUP BY → HAVING → ORDER BY. Therefore, GROUP BY must come after the WHERE clause when both are present, but before ORDER BY.

AI explanation

Standard SQL clause order is SELECT ... FROM ... WHERE ... GROUP BY ... HAVING ... ORDER BY, so when a WHERE clause is present, GROUP BY must be written immediately after it (rows are filtered first, then grouped). Placing GROUP BY before FROM/WHERE, or after ORDER BY, would violate this required syntax order and the query wouldn't parse correctly.