Bird
0
0

Given tables:

medium📝 query result Q4 of 15
SQL - LEFT and RIGHT JOIN
Given tables:

Products:
ProductID | Name
1 | Pen
2 | Pencil
3 | Eraser

Sales:
SaleID | ProductID
101 | 1
102 | 3

What is the result of:
SELECT Products.Name, Sales.SaleID FROM Products LEFT JOIN Sales ON Products.ProductID = Sales.ProductID;?
APen NULL, Pencil NULL, Eraser NULL
BPen 101, Pencil NULL, Eraser 102
CPen 101, Pencil 102, Eraser NULL
DPen 101, Pencil 102, Eraser 102
Step-by-Step Solution
Solution:
  1. Step 1: Match Products with Sales

    Pen (ProductID 1) matches SaleID 101; Eraser (3) matches 102; Pencil (2) has no sale.
  2. Step 2: Apply LEFT JOIN result

    All Products appear; Pencil's SaleID is NULL because no matching sale.
  3. Final Answer:

    Pen 101, Pencil NULL, Eraser 102 -> Option B
  4. Quick Check:

    LEFT JOIN unmatched right rows = NULL [OK]
Quick Trick: LEFT JOIN shows NULL for unmatched right table rows [OK]
Common Mistakes:
MISTAKES
  • Assuming unmatched rows are excluded
  • Mixing up SaleID values
  • Expecting all SaleIDs to appear

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes