1. Home
  2. Data Science
  3. SQL for Data Analysis
  4. What is the difference between the WHERE and HAVING…

Added 30 Nov -0001

What is the difference between the WHERE and HAVING clauses in SQL?

  1. WHERE filters groups; HAVING filters individual rows
  2. WHERE works only with numeric columns; HAVING works with text
  3. Both are interchangeable in every standard query
  4. WHERE filters rows before grouping; HAVING filters groups Correct answer

Correct answer

D. WHERE filters rows before grouping; HAVING filters groups

15 views

MCQSEXAM

Explanation

WHERE runs before GROUP BY and removes individual rows, so it cannot reference aggregate functions such as SUM, while HAVING runs after grouping and filters whole groups on aggregate results. A query can use both: WHERE to trim the input and HAVING to keep only groups that meet a threshold. Logically the clauses execute FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY in that order.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is D? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More SQL for Data Analysis MCQs

Practise all SQL for Data Analysis MCQs

Similar MCQs