Ask Precise Questions · practice
Filter One Category with WHERE
The four-column search is informative, but it still answers with the whole catalog. Suppose Riley needs a tool for a repair session. Events equipment and electronics would only make that answer harder to scan.
Open search.sql and add one line between FROM items and the semicolon:
SELECT asset_tag, name, category, loan_days
FROM items
WHERE category = 'tools';
Press Run. SQLite should keep the same four headings while returning only the two tool rows:
Columns: asset_tag | name | category | loan_days
TL-220 | Step ladder | tools | 3
TL-100 | Cordless drill | tools | 7
SELECT still decides which columns appear. The new WHERE clause makes a different decision: which source rows are allowed into the result. Read category = 'tools' as a comparison. For each item row, SQLite compares the stored category with the text tools and keeps the row when they are equal.
The quote marks matter because tools is a text category is not quoted here. It tells SQLite where to look; 'tools' is the value to look for.
You can check the decision against one visible row. For the step ladder, category contains tools, so the comparison is true and SQLite keeps the row. For the projector, it contains electronics, so the comparison is false and that row stays out.
Notice that the query does not say “anything except events.” A catalog may contain categories you have not seen, and those should not slip into a tools-only answer. Naming the category you want makes the question precise.
The order of the two matching rows still comes from this particular run, not from a rule in your SQL. We will make order part of the question soon. For this exercise, both tool rows matter, whichever one SQLite happens to return first.
Submit tries the same question with different item names, categories, and loan periods. If a non-tool appears, check the comparison after WHERE. If a tool is missing, make sure the filter compares category with exactly 'tools' and that the original four-column SELECT remains intact.
Your query now makes two separate choices cleanly: four useful details for each answer, and only the rows that belong to the requested category.
Task
Add a WHERE clause to search.sql so the four-column result contains only items whose category is 'tools'.
Run the query, confirm that every returned row is a tool, and submit it.