Bird
0
0

Given tables authors(id, name) and books(author_id, title), what will this query return?

medium📝 query result Q4 of 15
SQL - LEFT and RIGHT JOIN
Given tables authors(id, name) and books(author_id, title), what will this query return?
SELECT a.name FROM authors a LEFT JOIN books b ON a.id = b.author_id WHERE b.author_id IS NULL;
AAuthors who have written at least one book
BAuthors who have not written any books
CAll authors regardless of books
DBooks without authors
Step-by-Step Solution
Solution:
  1. Step 1: LEFT JOIN authors with books

    All authors are included; books matched by author_id or NULL if none.
  2. Step 2: Filter authors with no books

    WHERE b.author_id IS NULL selects authors without any matching book.
  3. Final Answer:

    Authors who have not written any books -> Option B
  4. Quick Check:

    LEFT JOIN + NULL filter = authors without books [OK]
Quick Trick: LEFT JOIN + NULL in right table finds unmatched left rows [OK]
Common Mistakes:
MISTAKES
  • Thinking it returns authors with books
  • Confusing NULL filter logic
  • Assuming INNER JOIN behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes