Bird
0
0

Given these tables:

medium📝 query result Q4 of 15
SQL - Table Relationships
Given these tables:
CREATE TABLE Author (AuthorID INT PRIMARY KEY, Name VARCHAR(50));
CREATE TABLE AuthorBio (AuthorID INT PRIMARY KEY, Biography TEXT, FOREIGN KEY (AuthorID) REFERENCES Author(AuthorID));
What will this query return?
SELECT Author.Name, AuthorBio.Biography FROM Author LEFT JOIN AuthorBio ON Author.AuthorID = AuthorBio.AuthorID;
AAll biographies with their authors; NULL if no author exists
BOnly authors who have biographies
CAll authors with their biographies; NULL if no biography exists
DAn error because of mismatched primary keys
Step-by-Step Solution
Solution:
  1. Step 1: Understand LEFT JOIN

    LEFT JOIN returns all rows from the left table (Author) and matching rows from the right table (AuthorBio).
  2. Step 2: Check for missing matches

    If an author has no biography, AuthorBio.Biography will be NULL.
  3. Final Answer:

    All authors with their biographies; NULL if no biography exists correctly describes the result.
  4. Quick Check:

    LEFT JOIN includes all left rows with NULLs for missing right rows [OK]
Quick Trick: LEFT JOIN returns all left rows, NULLs if no match [OK]
Common Mistakes:
MISTAKES
  • Confusing LEFT JOIN with INNER JOIN
  • Assuming only matched rows are returned
  • Thinking primary key mismatch causes query error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes