Search code examples
mysqldatabasekeywordansi-sql

Is there an ANSI SQL alternative to the MYSQL LIMIT keyword?


Is there an ANSI SQL alternative to the MYSQL LIMIT keyword?

The LIMIT keyword limits the number of rows returned by a SELECT e.g:

SELECT * FROM People WHERE Age > 18 LIMIT 2;

returns 2 rows.

SELECT * FROM People WHERE Age > 18 LIMIT 10, 2;

returns 2 rows after the first 10.


Solution

  • this shows the different ways:

    -- DB2
    select * from table fetch first 10 rows only 
    -- Informix 
    select first 10 * from table 
    -- Microsoft SQL Server and Access 
    select top 10 * from table 
    -- MySQL and PostgreSQL 
    select * from table limit 10 
    -- Oracle 
    select * from (select * from table) where rownum <= 10