SQL

Using LIMIT

Limiting Results with LIMIT

The LIMIT clause restricts the number of rows returned. This is essential when working with large tables!

Syntax

SELECT * FROM table_name
LIMIT number;

Why Use LIMIT?

  • Performance — avoid loading millions of rows when you only need a few
  • Preview data — quickly see what a table looks like
  • Top-N queries — find the top/bottom items

Common Patterns

-- Quick preview: just see 5 rows
SELECT * FROM products LIMIT 5;

-- Top 3 most expensive products SELECT * FROM products ORDER BY price DESC LIMIT 3;

-- 3 cheapest products SELECT * FROM products ORDER BY price LIMIT 3;

⚠️ Important Order

The correct query order is:

  • SELECT
  • FROM
  • WHERE (optional)
  • ORDER BY (optional)
  • LIMIT (always last!)

Your Task

Select the 3 cheapest products (lowest price first).

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.