0
0
MySQLquery~30 mins

ORDER BY single column in MySQL - Mini Project: Build & Apply

Choose your learning style9 modes available
Sorting Products by Price Using ORDER BY
📖 Scenario: You work at an 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: Build 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 exactly three products with given names and prices.
Write a query to select all columns from products.
Use ORDER BY price to sort the results by price ascending.
💡 Why This Matters
🌍 Real World
Sorting products by price is common in online stores to help customers find affordable or premium items easily.
💼 Career
Knowing how to use ORDER BY is essential for database querying jobs, data analysis, and backend development.
Progress0 / 4 steps
1
Create the products table and insert data
Write SQL statements to create a table called products with columns id (integer), name (text), and price (decimal). Then insert these three products exactly: (1, 'Pen', 1.20), (2, 'Notebook', 2.50), and (3, 'Pencil', 0.80).
MySQL
Need a hint?

Use CREATE TABLE to make the table. Use INSERT INTO with multiple rows to add the products.

2
Write a basic SELECT query
Write a SQL query to select all columns from the products table. Use SELECT * FROM products.
MySQL
Need a hint?

Use SELECT * FROM products; to get all rows and columns.

3
Add ORDER BY to sort by price ascending
Modify the SELECT query to add ORDER BY price so the products are sorted by the price column in ascending order.
MySQL
Need a hint?

Add ORDER BY price after the FROM clause to sort by price ascending.

4
Complete the query with explicit ASC keyword
Add the keyword ASC after ORDER BY price to explicitly specify ascending order.
MySQL
Need a hint?

Write ORDER BY price ASC to show ascending order explicitly.