Can you remove one old library loan without losing the others?
Your school's practice library database has one old loan that needs removing. You know its loan ID is twenty-four. How can you check that your command will pick that one record before you delete anything?
Each row in Loans stores one loan, with an ID and a return note. When you add a row using insert into and values, you give it an unused loan ID. Loan ID is the primary key, so no two rows can have the same ID.
The star means show all columns from Loans. Where loan ID equals twenty-four filters the rows. Seventeen fails, twenty-four matches, and forty-two fails. The result shows loan twenty-four and its return note. The original table stays unchanged.
There are three loan IDs in the table: seventeen, twenty-four and forty-two. If you change the where condition in the select query to loan ID equals seventeen, which rows will it show? Pick an answer.
First, select from Loans where loan ID equals twenty-four. You should see just that loan. Next, delete from Loans using the same where condition. Finally, select all the remaining rows and use order by loan ID ascending to show them from lowest ID to highest.
Start again with all three original loans. This time your select preview shows only loan forty-two. You run delete with that same where condition, then select all rows. Which loan IDs should you see? Pick an answer.
Back in the worked example, your final query lists loan seventeen before loan forty-two because you sorted by ID in ascending order. Loan twenty-four is gone, and both remaining return notes still say returned on time.
Start with loan twenty-four still in the table. If you use delete from Loans where loan ID equals twenty-four, the whole row goes. To clear just the note, update Loans and set ReturnNote to two single quotes with nothing between them, where loan ID equals twenty-four. The row stays.
An exam question might say, 'Explain why a where condition is needed in this delete statement.' Your answer should name the effect: it limits deletion to the row with loan ID twenty-four. Without where, delete from Loans would remove every row in the table.