Can you make a school library database show only book titles and copy counts?
Your school library needs a quick list of book titles and how many copies it has. The database also stores a number for each book. How can you ask it to leave those numbers off the list?
Each row in your practice book table is one book record. The first field, book underscore ID, gives each record a unique number. The next two fields are title and copies. Look at the first row: book one hundred and one is River Walk, and the library has four copies.
First, you see title and copies grouped together. Book ID is left out. SELECT names the fields you want in the result. Follow the arrow to book, the table those fields come from. FROM names that source table.
You’ve put title and copies after SELECT. Now you need to tell the database where those fields are stored. What should you write after FROM? Pick one answer.
On the first line, write SELECT title, comma, copies. The comma separates the two field names, and title will appear first in the result. On the next line, write FROM book and finish with a semicolon.
Run your query on the practice database. The result shows title first and copies second. In this run, you see River Walk with four, City Birds with two, and Night Trains with seven. All three rows appear. Without ORDER BY, their order isn’t guaranteed. The stored table hasn’t changed.
Now the librarian wants the book ID and copy count for every book, with the ID first. For example, one result row should show one hundred and two, then two. Pick the query that would produce that list.
On the left, River Walk and four are fixed values. If you use them with FROM book, you get the same pair on every result row. On the right, title and copies are field names. They tell the database to read the stored values from each row.
An AQA question might say, ‘Write an SQL query to display the title and book ID of every book, with title first.’ Use title and book underscore ID in that order after SELECT, then give the table name after FROM.