Project: the store's search box
SQL · Unit 2: Filtering
- Full plan
- SQL
- Project
- 3 exercises
A store's search box is a WHERE that someone builds without knowing it. They pick a category, set a top price, type a few letters, and each of those becomes a condition.
This is the search of someone who picked Accessories and a cap of 20. Look at what it offers them: the Cable, which is out of stock. This search box is missing a filter.
SELECT name, price, stock
FROM products
WHERE category = 'Accessories'
AND price <= 20;Returns
| name | price | stock |
|---|---|---|
| Mouse | 19.9 | 30 |
| Cable | 5.25 | 0 |
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Put the lines in order
Someone types the letter
Mand sets a cap of 100. Put their search in order. One line doesn't belong.2. Write the code
Someone else picks the Audio category and a price from 50 to 70, both ends included. Finish the query so it shows the
nameand theprice, in that order, of what it finds.3. Write the code
The whole search box. Someone types the letter
a, sets a cap of 100, and checks the box for in-stock items only. Write a query that shows thenameand theprice, in that order, of the products that fit all three: the name containsa, they cost 100 or less, and they're in stock.
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.