Bird
0
0

Consider these tables:

medium📝 query result Q5 of 15
SQL - LEFT and RIGHT JOIN
Consider these tables:

Authors
id | name
1 | John
2 | Mary

Books
author_id | title
1 | SQL Basics
1 | Advanced SQL

What will this query return?

SELECT Authors.name, Books.title FROM Authors LEFT JOIN Books ON Authors.id = Books.author_id WHERE Books.title = 'SQL Basics';
AJohn | SQL Basics<br>Mary | NULL
BMary | NULL
CJohn | SQL Basics<br>John | Advanced SQL
DJohn | SQL Basics
Step-by-Step Solution
Solution:
  1. Step 1: Analyze WHERE with LEFT JOIN

    WHERE filters after join; condition on right table column excludes rows where Books.title is NULL.
  2. Step 2: Identify matching rows

    Only John has 'SQL Basics' book; Mary is excluded because Books.title is NULL for her.
  3. Final Answer:

    John | SQL Basics -> Option D
  4. Quick Check:

    WHERE on right table filters out unmatched left rows [OK]
Quick Trick: WHERE on right table column filters out unmatched left rows [OK]
Common Mistakes:
MISTAKES
  • Expecting unmatched left rows to appear despite WHERE on right table
  • Confusing LEFT JOIN with INNER JOIN behavior
  • Ignoring NULL filtering effect of WHERE

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes