Book Suggestions from Reading Buddies
Problem
Table: `Buddies`
```text
+-----------+------+
| Column | Type |
+-----------+------+
| reader_a | int |
| reader_b | int |
+-----------+------+
(reader_a, reader_b) is the primary key. Each row means reader_a and reader_b
are reading buddies. The relationship is mutual but is stored once, in either
order of the two ids.
```
Table: `Reads`
```text
+-----------+---------+
| Column | Type |
+-----------+---------+
| reader_id | int |
| book_id | int |
+-----------+---------+
(reader_id, book_id) is the primary key. Each row means reader_id has read
book_id.
```
Suggest books to **reader 1** based on what their reading buddies have read. Do not suggest a book reader 1 has already read. Return each suggested book once.
Return the column `suggested_book` with no duplicates, in any order.
Tables
Example rows — the live problem includes the full dataset.
| reader_a | reader_b |
|---|---|
| 1 | 2 |
| 1 | 3 |
| 1 | 4 |
| reader_id | book_id |
|---|---|
| 1 | 88 |
| 2 | 23 |
| 3 | 24 |
Expected output
Your answer should return 5 rows with the columns suggested_book.
Starter code (SQL)
SELECT *
FROM Buddies;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock