Bird
0
0

What will be the result of this query?

medium📝 query result Q5 of 15
SQL - LEFT and RIGHT JOIN
What will be the result of this query?
SELECT Orders.id, Customers.name FROM Orders RIGHT JOIN Customers ON Orders.customer_id = Customers.id;
AAll customers with their orders; NULL if no order exists.
BOnly orders that have customers.
CAll orders with matching customer names; NULL if no customer.
DOnly customers that have orders.
Step-by-Step Solution
Solution:
  1. Step 1: Understand RIGHT JOIN behavior

    RIGHT JOIN keeps all rows from the right table (Customers) and matches from the left table (Orders). Unmatched left columns are NULL.
  2. Step 2: Analyze query output

    Query returns all customers with their orders or NULL if no order exists.
  3. Final Answer:

    All customers with their orders; NULL if no order exists. -> Option A
  4. Quick Check:

    RIGHT JOIN output = C [OK]
Quick Trick: RIGHT JOIN keeps all right rows, unmatched left columns are NULL [OK]
Common Mistakes:
MISTAKES
  • Confusing which table is left or right
  • Assuming unmatched rows are excluded
  • Mixing up NULL placement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes