BBampaa

Lessons › SQL › Chapter 1: Reading data

SQL lesson

LIMIT

LIMIT keeps only the first few rows, like LIMIT 3 for three rows. It goes at the very end. On its own, LIMIT doesn't pick the biggest or newest. Sort with ORDER BY first, and LIMIT gives you the top few.

Try this lesson free →
About 5–10 minutes · no sign-up needed

Example

Just the first few rows

SELECT *
FROM orders
LIMIT 5

Result:

Step by step

  1. Keeps only the first 3 rows.
    SELECT * FROM orders LIMIT 3
  2. LIMIT goes last, after everything else.
    SELECT * FROM orders LIMIT 3
  3. Sort first, and LIMIT gives you the top 3.
    SELECT * FROM orders LIMIT 3

Practice

Try each one in your head first, then open the answer.

1. Write a query to show only the first 3 rows from the orders table.
SELECT * FROM orders LIMIT 3
2. Write a query to show only the first 2 rows from the products table.
SELECT * FROM products LIMIT 2
3. Write a query to show only the first 2 rows from the store_sales table.
SELECT * FROM store_sales LIMIT 2
4. Write a query to show only the first 3 rows from the reviews table.
SELECT * FROM reviews LIMIT 3
5. Write a query to show only the full_name and role of the first 3 rows from the employees table.
SELECT full_name, role FROM employees LIMIT 3

Learn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.

Try this lesson free →
About 5–10 minutes · no sign-up needed