AnalystPath

Book Suggestions from Reading Buddies

SQLMediumMid level~15 min

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.

Buddies
reader_areader_b
12
13
14
Reads
reader_idbook_id
188
223
324

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

Related SQL questions