SQL Beginner Challenge 3: Sort Results with ORDER BY

Difficulty: Beginner
Estimated time: 5–10 minutes
SQL concepts: ORDER BY, sorting results, ascending vs descending
Goal: Control the order of your query results.

The Scenario

You’re reviewing the product list again, but this time the product manager wants the results sorted by price, from the cheapest to the most expensive.

By default, SQL does not guarantee any specific order — so you need to explicitly tell the database how to sort the results.

Database Table

products

column_nametypedescription
product_idINTEGERUnique product ID
nameTEXTProduct name
categoryTEXTProduct category
priceDECIMALProduct price
stock_qtyINTEGERUnits in stock
created_atTIMESTAMPWhen the product was created

Sample Data (for context)

product_idnamecategorypricestock_qty
101Wireless MouseAccessories24.99120
102Mechanical KeyboardAccessories89.0045
10327-inch MonitorDisplays229.9918
104USB-C HubAccessories34.5070
105Laptop StandWorkspace39.9932

Your Task

Write a SQL query that returns:

  • name
  • price
  • category

Sorted by price in ascending order (lowest price first).

Expected Output

namepricecategory
Wireless Mouse24.99Accessories
USB-C Hub34.50Accessories
Laptop Stand39.99Workspace
Mechanical Keyboard89.00Accessories
27-inch Monitor229.99Displays

Constraints

  • Do not use SELECT *
  • Use ORDER BY to sort results
  • Sort by price from lowest to highest
  • Column order must be: name, price, category

Hint (Optional)

By default, ORDER BY sorts values in ascending order.
You can also specify ASC or DESC explicitly.

SELECT
name,
price,
category
FROM products
ORDER BY price;

Explanation

  • ORDER BY price tells SQL how to sort the result set.
  • Ascending order (ASC) is the default.
  • Without ORDER BY, the database may return rows in any order.

Common Mistakes

  1. Assuming results are automatically sorted
  2. Putting ORDER BY before FROM
  3. Sorting by a column not included in the query (database-dependent behavior)

Optional Extension (Mini Bonus)

Try:

  • Sorting by price from highest to lowest
  • Sorting by category first, then price
  • Combining WHERE and ORDER BY

🔗 View reference solution on GitHub
(After you’ve tried the challenge)

Next Challenge

Beginner Challenge #4: Count Rows with COUNT()

Want more practical SQL challenges?
Subscribe to the Solve With SQL newsletter and get new problems delivered to your inbox.