SQL

ORDER BY Ascending

Sorting Results with ORDER BY

The ORDER BY clause sorts your results in a specific order. Without it, SQL returns rows in no guaranteed order!

Syntax

SELECT columns FROM table_name
ORDER BY column_name;

By default, results are sorted in ascending order:

  • Numbers: 0, 1, 2, 3...
  • Text: A, B, C, D...
  • Dates: earliest first

Examples

-- Sort by price (cheapest first)
SELECT * FROM products ORDER BY price;

-- Sort alphabetically by name SELECT * FROM products ORDER BY name;

-- Sort by category SELECT * FROM products ORDER BY category;

💡 Why Sorting Matters

Sorting helps you:

  • Find the cheapest/most expensive items
  • See data in chronological order
  • Present results in a readable way

⚠️ Important

ORDER BY always comes near the end of the query, after WHERE (if present).

Your Task

Select all products and order them by price (lowest to highest).

query.sql
Loading SQL engine...
Downloading SQL engine… (one-time)

Downloading SQL engine… (one-time)

This runs entirely in your browser and is cached for next time.