Easy Filtering rows Shop database

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

Press Run to see your query's result, or Check answer to compare it with the expected result.

Expected result

namecategoryprice
MonitorDisplays189
WebcamVideo59

Rows can come in any order. Column names do not have to match.

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.

Want to try the query on MySQL or PostgreSQL? Open it in the SQL Online Compiler or SQLite Online.