Can a York library list your borrowed books when its loan records have no titles?
You ask a library in York for a list of the books you've borrowed. Its loan records have your member number and the book numbers, but the titles are stored somewhere else. How can one query put that list together?
Look at the Book table. Each row has a book number and a title. In a query on this table, Select picks columns, Where filters rows and Order By sorts the results. You can list the titles from here, but this table doesn't tell you who borrowed them.
Start with book number twenty-one in the Loan row. Follow it to the Book row with the same number and read the title: The Hobbit. Book ID is the primary key in Book. In Loan, Book ID is a foreign key that refers to it.
You find a Loan row with member ID seven and book ID thirty-four. Think about which number points to the book. Which Book row should match this loan? Pick one answer.
After matching the book numbers, you can read the title beside each loan. Keep the first row, The Hobbit, because it's for member seven. Leave out Matilda because it's for member nine. Keep the last row, A Monster Calls, because it's for member seven too.
Select Book dot Title from Book and Loan. After Where, set Book dot Book ID equal to Loan dot Book ID to match the rows. And adds the filter for member seven. Order By sorts the titles in ascending order, so A Monster Calls comes before The Hobbit.
You want member nine's borrowed titles instead. Keep the two tables, the book ID match and the alphabetical sort. Which line should replace the member filter so the query returns Matilda? Pick one answer.
Leave out the book ID match and each of member seven's two loans pairs with all three books. You get six rows, with Matilda appearing twice. Put the match back and each loan pairs only with its own book. You get two rows, with no Matilda.
To add loan fifty-one for member nine and book twenty-one, use Insert Into with Values. To correct the book number to thirty-four, use Update and Set. To remove the loan, use Delete From. For the edit and the deletion, Where uses the unique loan number to target one row.