Bird
0
0

Given these tables:

medium📝 query result Q4 of 15
SQL - Table Relationships
Given these tables:
Authors(AuthorID, Name)
Books(BookID, Title, AuthorID)
What will this query return?
SELECT Name, COUNT(BookID) AS BookCount FROM Authors LEFT JOIN Books ON Authors.AuthorID = Books.AuthorID GROUP BY Name;
AEach author with the number of books they wrote, including authors with zero books
BOnly authors who have written at least one book with their book count
CAll books with their authors' names repeated for each book
DAn error because GROUP BY is missing AuthorID
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the LEFT JOIN

    LEFT JOIN keeps all authors even if they have no matching books.
  2. Step 2: Understand GROUP BY and COUNT

    Grouping by author name counts books per author; authors with no books show count 0.
  3. Final Answer:

    Each author with the number of books they wrote, including authors with zero books -> Option A
  4. Quick Check:

    LEFT JOIN + GROUP BY = all authors with book counts [OK]
Quick Trick: LEFT JOIN keeps all 'one' side rows even without matches [OK]
Common Mistakes:
MISTAKES
  • Thinking authors with zero books are excluded
  • Confusing LEFT JOIN with INNER JOIN
  • Assuming GROUP BY needs AuthorID instead of Name

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes