Sorting Products by Price Using ORDER BY
📖 Scenario: You work at a small online store. You have a table of products with their prices. You want to see the products sorted by their price from lowest to highest.
🎯 Goal: Create a SQL query that selects all products and sorts them by the price column in ascending order using ORDER BY.
📋 What You'll Learn
Create a table called
products with columns id, name, and price.Insert three products with exact values: (1, 'Pen', 1.20), (2, 'Notebook', 2.50), (3, 'Eraser', 0.80).
Write a SQL query to select all columns from
products.Use
ORDER BY price to sort the results by the price column in ascending order.💡 Why This Matters
🌍 Real World
Sorting products by price helps customers find cheaper or more expensive items easily on online stores.
💼 Career
Knowing how to use ORDER BY is essential for database querying and reporting in many jobs like data analysis, backend development, and database administration.
Progress0 / 4 steps