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?
- SELECT a.name, b.title FROM Authors a INNER JOIN Books b ON a.author_id = b.author_id;
- SELECT a.name, b.title FROM Authors a LEFT JOIN Books b ON a.author_id = b.author_id;
- SELECT a.name, b.title FROM Books b LEFT JOIN Authors a ON a.author_id = b.author_id;
- 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
- Table Staff: emp_id | name | manager_id 1 | Nandini | NULL 2 | Omkar | 1 3 |…
- Table Riders: rider_id | name 1 | Manoj 2 | Nisha 3 | Om Table Trips: trip_id…
- Table Riders: rider_id | name 1 | Manoj 2 | Nisha 3 | Om Table Trips: trip_id…
- Table Teams: team_id | team | city 1 | CSK | Chennai 2 | MI | Mumbai 3 | RCB |…
- Table Riders: rider_id | name 1 | Manoj 2 | Nisha 3 | Om Table Trips: trip_id…
- Table Invoices: inv_id | customer | total 1 | Zoya | 1000 2 | Arun | 500 Table…
- Table Staff: emp_id | name | manager_id 1 | Nandini | NULL 2 | Omkar | 1 3 |…
- Table A has m rows. Table B has n rows and B.k is its primary key. How many…
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