Why data lives in several tables
Keys connect tables; JOIN follows them.
The loans table does not store the book title or the member name. It stores book_id and member_id: numbers that point to a row in books and in members. Each table has a primary key (id) that is unique for every row, and a column that points to another table's key is called a foreign key. This way each fact is stored once. JOIN follows these pointers to bring the matching rows together.
SELECT loans.id, books.title
FROM loans
JOIN books ON loans.book_id = books.id;For every loan, finds the book whose id equals the loan's book_id and shows its title next to the loan id.
ON says how rows match. Here: a loan matches the book whose id is the loan's book_id.
When two tables both have a column called id, write table.column (loans.id, books.id) so the database knows which you mean.