1. Home
  2. Data Science
  3. SQL for Data Analysis
  4. What happens to LEFT JOIN orders o ON ... WHERE o.status =…

Added 30 Nov -0001

What happens to LEFT JOIN orders o ON ... WHERE o.status = 'paid' when o.status is NULL for unmatched rows?

  1. Unmatched rows are kept with a NULL status
  2. Unmatched rows are kept with their status set to the string 'paid'
  3. The query returns no rows at all
  4. The query behaves like an inner join, dropping unmatched orders Correct answer

Correct answer

D. The query behaves like an inner join, dropping unmatched orders

15 views

MCQSEXAM

Explanation

A LEFT JOIN pads unmatched right-side columns with NULL, but the WHERE predicate then tests those NULLs and the comparison evaluates to unknown, so the rows are filtered out. The result is that the outer join silently becomes an inner join. To keep the outer semantics, put the condition in the ON clause, or allow NULL explicitly with o.status = 'paid' OR o.status IS NULL.

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