bubble_chart StackLab

Database Migration

19 steps · pending Not started · person_outline Guest
arrow_back Back

Test the table relationships

The real benefit of relational databases becomes clear when we combine data from multiple tables. Run:

code sql
SELECT
    br.borrow_id,

    s.student_id,
    CONCAT(
        s.student_first_name,
        ' ',
        s.student_last_name
    ) AS student_name,

    s.student_course,

    b.book_id,
    b.book_title,
    b.book_author,
    b.book_category,

    br.borrow_date,
    br.borrow_return_date

FROM borrow br

INNER JOIN students s
    ON br.student_id = s.student_id

INNER JOIN books b
    ON br.book_id = b.book_id

ORDER BY br.borrow_date DESC;
You should get a result similar to:
code text
borrow_id | student_name    | course        | book_title
------------------------------------------------------------
3         | RON EDMUND      | BSEE          | 1984
2         | JAN XAVIER      | BSA-AGRONOMY  | Project Hail Mary
1         | CLIFF AMADEUS   | BSIT          | Jurassic Park
Instead of storing the student's name and book title repeatedly inside borrow, we use their IDs to connect the tables. This is one of the main ideas behind a relational database.

login Sign in to save your progress permanently. info Progress is saved in your browser session
format_list_numbered Step 14 of 19