Bird
0
0

You have tables:

hard📝 Application Q8 of 15
SQL - LEFT and RIGHT JOIN
You have tables:
Authors:
AuthorID | Name
1 | John
2 | Mary

Books:
BookID | AuthorID | Title
101 | 1 | SQL Basics
102 | 3 | Advanced SQL

Write a query using RIGHT JOIN to list all books with their authors' names, showing NULL for authors not in Authors table. Which query is correct?
ASELECT Books.Title, Authors.Name FROM Authors LEFT JOIN Books ON Authors.AuthorID = Books.AuthorID;
BSELECT Books.Title, Authors.Name FROM Books RIGHT JOIN Authors ON Books.AuthorID = Authors.AuthorID;
CSELECT Books.Title, Authors.Name FROM Authors RIGHT JOIN Books ON Authors.AuthorID = Books.AuthorID;
DSELECT Books.Title, Authors.Name FROM Books LEFT JOIN Authors ON Books.AuthorID = Authors.AuthorID;
Step-by-Step Solution
Solution:
  1. Step 1: Identify right table

    We want all books listed, so Books is right table.
  2. Step 2: Write RIGHT JOIN with Authors as left, Books as right

    Authors RIGHT JOIN Books ON Authors.AuthorID = Books.AuthorID is correct.
  3. Final Answer:

    SELECT Books.Title, Authors.Name FROM Authors RIGHT JOIN Books ON Authors.AuthorID = Books.AuthorID; -> Option C
  4. Quick Check:

    RIGHT JOIN keeps all books, authors NULL if missing = SELECT Books.Title, Authors.Name FROM Authors RIGHT JOIN Books ON Authors.AuthorID = Books.AuthorID; [OK]
Quick Trick: RIGHT JOIN keeps all right table rows, unmatched left columns NULL [OK]
Common Mistakes:
MISTAKES
  • Swapping left and right tables
  • Using LEFT JOIN instead of RIGHT JOIN
  • Incorrect ON clause columns

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes