SQL Tutorial SQL Advanced SQL Database SQL References

SQL LIMIT Keyword



The SQL LIMIT keyword is used to fetch specified number of records from a table. This is useful when the table contains thousands of records and returning a large dataset can impact performance. This keyword is supported by MySQL database.

Note: LIMIT keyword is not supported in all database. For example SQL Server and MS Access supports TOP keyword and Oracle supports the ROWNUM keyword to fetch limited number of records.

Syntax

The syntax for using LIMIT keyword is given below:

SELECT column1, column2, ...
FROM table_name
WHERE condition(s)
LIMIT number;

Example:

Consider a database containing a table called Employee with the following records:

EmpIDNameCityAgeSalary
1JohnLondon253000
2MarryNew York242750
3JoParis272800
4KimAmsterdam303100
5RameshNew Delhi283000
6HuangBeijing282800

  • To fetch top 3 records from the Employee table, the SQL query is:

    SELECT * FROM Employee LIMIT 3;
    

    This will produce the result as shown below:

    EmpIDNameCityAgeSalary
    1JohnLondon253000
    2MarryNew York242750
    3JoParis272800

❮ SQL Keywords

5