Filter Products by Price Range Using WHERE with BETWEEN
📖 Scenario: You are managing a small online store database. You want to find products within a specific price range to create a special discount list.
🎯 Goal: Build a SQL query that selects products priced between two given values using the WHERE clause with BETWEEN.
📋 What You'll Learn
Create a table called
products with columns id, name, and price.Insert exactly these products with prices:
(1, 'Pen', 5), (2, 'Notebook', 15), (3, 'Backpack', 45), (4, 'Calculator', 55), (5, 'Desk Lamp', 35).Define two variables
min_price and max_price with values 10 and 40 respectively.Write a SQL query that selects
name and price from products where price is between min_price and max_price.💡 Why This Matters
🌍 Real World
Filtering products by price range is common in online stores to show customers affordable options or special deals.
💼 Career
Knowing how to use WHERE with BETWEEN helps database professionals write efficient queries for filtering data based on ranges.
Progress0 / 4 steps