Match a list of values with IN
Question
Show the name, category and price of products in the Video or Displays category.
customersid, name, country, joined_on
productsid, name, category, price
ordersid, customer_id, ordered_on, status
order_itemsorder_id, product_id, quantity
Your query
Ctrl+Enter to run
Result
Expected result
| name | category | price |
|---|---|---|
| Monitor | Displays | 189 |
| Webcam | Video | 59 |
Hint
IN (a, b) is a shorter way to write = a OR = b.
Show the solution
solution.sql
Run this code
SELECT name, category, price
FROM products
WHERE category IN ('Video', 'Displays');
Why it works
IN checks whether the value is one of the listed values. It reads well and is easy to extend when the list grows.
Common mistake
Text values need quotes. IN (Video, Displays) makes SQL look for columns called Video and Displays and fails.