LIMIT restricts the number of rows returned by a query in database systems that support LIMIT syntax. It is commonly used with ORDER BY to retrieve a specific number of top results.
Analysts often need only the top few results instead of retrieving an entire joined dataset.
Return the ten largest orders with customer information.
SELECT
c.CustomerName,
o.OrderID,
o.OrderAmount
FROM Customers c
INNER JOIN Orders o
ON c.CustomerID = o.CustomerID
ORDER BY o.OrderAmount DESC
LIMIT 10;
Used for top-N reports, previews, dashboards, testing, and data exploration.
- LIMIT restricts returned rows in supported databases.
- ORDER BY should usually be used for meaningful top-N results.
- Syntax differs across database platforms.
- LIMIT is useful for exploration.
- It does not reduce the logical JOIN relationship.
Why use ORDER BY with LIMIT?
ORDER BY determines which rows are considered the top or bottom records before LIMIT restricts the result.
Is LIMIT supported identically by every database?
No. Different database systems may use different syntax for limiting rows.