Multiple choice technology databases

In a select with a group by clause, a where clause, and a having clause, the where conditions are applied before the having conditions?

  1. True

  2. False

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

In SQL query execution, WHERE clause filters individual rows BEFORE grouping, while HAVING clause filters groups AFTER aggregation. The logical order is: FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY. WHERE cannot use aggregate functions, but HAVING can. This is why WHERE conditions are applied first to reduce the row set before grouping.

AI explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) True - This option is correct. In a SQL SELECT statement with a GROUP BY clause, the WHERE clause is applied before the HAVING clause. The WHERE clause filters the rows before they are grouped, while the HAVING clause filters the aggregated groups after they have been formed.

Option B) False - This option is incorrect. The WHERE clause is applied before the HAVING clause in a SQL SELECT statement with a GROUP BY clause.

The correct answer is A) True. This option is correct because the WHERE conditions are applied before the HAVING conditions in a SELECT statement with a GROUP BY clause.