SQL Joins · Question 15 · Medium

SQL Joins question 15

Tables Authors(author_id, name) and Books(book_id, title, author_id) exist. Which query lists every author with their book titles, including authors who have not written any book?

  1. SELECT a.name, b.title FROM Authors a INNER JOIN Books b ON a.author_id = b.author_id;
  2. SELECT a.name, b.title FROM Authors a LEFT JOIN Books b ON a.author_id = b.author_id;
  3. SELECT a.name, b.title FROM Books b LEFT JOIN Authors a ON a.author_id = b.author_id;
  4. SELECT a.name, b.title FROM Authors a RIGHT JOIN Books b ON a.author_id = b.author_id;
Answer and explanation

Answer: B. SELECT a.name, b.title FROM Authors a LEFT JOIN Books b ON a.author_id = b.author_id;

Explanation: The table whose rows must all be kept, Authors, has to be on the preserved side. Authors LEFT JOIN Books does that; the inner join drops authors without books, and the other two preserve Books instead.

Previous: Table Riders: rider_id | name 1 | Manoj 2 | Nisha 3 | Om Table Trips: trip_id… · Next: Table Teams: team_id | team | city 1 | CSK | Chennai 2 | MI | Mumbai 3 | RCB |…

Practise sql joins

Try a fresh set of sql joins questions with an explanation after every answer, free and without signing up: SQL Joins practice. Or sit a full placement mock test.

More sql joins questions

More sql practice

Aggregates & GROUP BY · Subqueries & CTEs · Window Functions · NULL Handling · SQL Functions & CASE · UNION, INTERSECT & EXCEPT · Tables, Keys & Constraints · DML & Transactions

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge