1. Home
  2. Data Science
  3. SQL for Data Analysis
  4. A LEFT JOIN carries the right-table condition b.status =…

Added 30 Nov -0001

A LEFT JOIN carries the right-table condition b.status = 'active' in the WHERE clause instead of the ON clause. What is the effect?

  1. Nothing changes, because the optimiser moves the predicate into the ON clause
  2. All inactive matches are kept while unmatched rows are duplicated
  3. The query fails because WHERE cannot reference the right table
  4. Rows with no matching b row are removed, turning the outer join into an effective inner join Correct answer

Correct answer

D. Rows with no matching b row are removed, turning the outer join into an effective inner join

13 views

MCQSEXAM

Explanation

Outer join predicate placement matters: a WHERE predicate on the right table evaluates to UNKNOWN for unmatched rows and filters them out, so the outer join behaves like an inner join. Putting the condition in ON filters matches before the join, preserving left rows with NULL-extended columns. This is one of the most common SQL interview traps.

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