Understand the database
Before writing SQL, let's look at what we're building. The system has three main tables:
text
students books
│ │
│ student_id │ book_id
│ │
└──────────┐ ┌─────────┘
▼ ▼
borrow
borrow table acts as the connection between students and books.
For example:
text
CLIFF AMADEUS → Jurassic Park
JAN XAVIER → Project Hail Mary
RON EDMUND → 1984
- One student can have many borrowing records.
- One book can appear in many borrowing records over time.
- Each borrowing record belongs to one student and one book.
- A
borrow_return_dateofNULLmeans the book has not been returned yet. - A non-
NULLborrow_return_datemeans the book has been returned.
Think of borrow as a transaction table. It records who borrowed which book and when.
Sign in to save your progress permanently.
Progress is saved in your browser session
Step 2 of 19