LIMIT – Control How Many Rows You Get

Quick Syntax

SELECT column1, column2
FROM table_name
ORDER BY column_name DESC
LIMIT number;

This tells SQL:

“Give me just the first few rows — stop after that many.”

Super useful when you’re dealing with a big table and just want the top 5, first 10, or latest 1.


Here’s the Table You’re Working With

Let’s say you have a table called orders:

a
order_id customer_name total_amount
1Brill Venn15.99
2Larka Tove45.00
3Brill Venn15.99
4Milo Kresh72.50
5Vesh Luro10.00
6Tola Jinn29.99

Suppose You Want the Top 3 Highest Orders

SELECT customer_name, total_amount
FROM orders
ORDER BY total_amount DESC
LIMIT 3;

Output:

Milo Kresh    72.50
Larka Tove    45.00
Tola Jinn     29.99

SQL sorted everything by total_amount, and then used LIMIT 3 to only show the top 3 rows. Great for a leaderboard or summary.


Suppose You Just Want the First 2 Orders by ID

SELECT order_id, customer_name
FROM orders
ORDER BY order_id ASC
LIMIT 2;

Output:

1   Brill Venn
2   Larka Tove

This shows the first two rows in the table, ordered by order_id. Useful for previews or testing.


Suppose You Want to Skip Some Rows (LIMIT + OFFSET)

You want to skip the first 2 orders and then show the next 3.

SELECT customer_name, total_amount
FROM orders
ORDER BY order_id
LIMIT 3 OFFSET 2;

Output:

3   Brill Venn
4   Milo Kresh
5   Vesh Luro

OFFSET 2 skips the first two rows, and LIMIT 3 shows the next three. This is especially helpful for pagination or “load more” features.


Recap – What You Learned

  • LIMIT controls how many rows SQL returns
  • Use with ORDER BY to grab top, bottom, or recent data
  • OFFSET skips rows before LIMIT kicks in
  • Works in MySQL, PostgreSQL, SQLite, and more
  • In SQL Server, use TOP instead

Next, check out BETWEEN — it helps you find results within a certain range (like amounts between 10 and 50).
See how it works here.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top