Toy example: I have a database schema shown in this EDR diagram:
- Student one-to-many with StudyGroup
- StudyGroup one-to-many with Borrowed
- Borrowed one-to-many with Books.
I want to get all books that have been borrowed by all study groups of a single Student.
+------------+---------+----------------+
| student.id | book.id | study_group.id |
+------------+---------+----------------+
| 1 | 1 | 1 |
| 1 | 2 | 1 |
| 1 | 3 | 1 |
| 1 | 4 | 2 |
| 1 | 1 | 2 |
+------------+---------+----------------+
I'm unsure how to construct the multiple joins in this case,
SELECT student.id, book.id, study_group.id
FROM ...
INNER JOIN...
INNER JOIN...
WHERE student.id == 1