SQL > Advanced SQL > Limit

The LIMIT clause restricts the number of results returned from a SQL statement. It is available in MySQL, Hive, and Google BigQuery.

The SQL LIMIT clause lets you cap the number of rows returned by a query — ideal for retrieving top records. Always pair it with ORDER BY to ensure predictable, meaningful results.

Syntax

The syntax for LIMIT is as follows:

[SQL Statement 1]
LIMIT [N];

where [N] is the number of records to be returned. Please note that the ORDER BY clause is usually included in the SQL statement. Without the ORDER BY clause, the results we get would be dependent on what the database default is.

Example

We use the following table for our example.

Table Store_Information

 Store_Name  Sales  Txn_Date 
 Los Angeles 1500  Jan-05-1999 
 San Diego 250  Jan-07-1999 
 San Francisco 300  Jan-08-1999 
 Boston 700  Jan-08-1999 

To retrieve the two highest sales amounts in Table Store_Information, we key in,

SELECT Store_Name, Sales, Txn_Date
FROM Store_Information
ORDER BY Sales DESC
LIMIT 2;

Result:

Store_Name Sales Txn_Date
Los Angeles 1500 Jan-05-1999
Boston 700 Jan-08-1999

The SQL Server equivalent to LIMIT is TOP.

Frequently Asked Questions

What does the SQL LIMIT clause do?
The SQL LIMIT clause restricts the number of rows returned by a query. For example, LIMIT 5 will return only the first 5 rows of the result set.
Which databases support the LIMIT clause?
LIMIT is supported in MySQL, Hive, and Google BigQuery. SQL Server uses TOP instead, while Oracle uses ROWNUM or FETCH FIRST n ROWS ONLY.
Should I use ORDER BY with LIMIT?
Yes, it is recommended to include an ORDER BY clause when using LIMIT. Without ORDER BY, the rows returned depend on the database's default row order, which can be unpredictable.
What is the SQL Server equivalent of LIMIT?
In SQL Server, the equivalent of LIMIT is the TOP clause. For example, SELECT TOP 2 * FROM table is equivalent to SELECT * FROM table LIMIT 2.

Next: SQL TOP

This page was last updated on March 19, 2026.




Copyright © 2026   1keydata.com   All Rights Reserved     Privacy Policy     About   Contact