Home >Database >Mysql Tutorial >How to Limit Rows in ANSI SQL and Different RDBMS?

How to Limit Rows in ANSI SQL and Different RDBMS?

Linda Hamilton
Linda HamiltonOriginal
2024-11-28 21:18:15891browse

How to Limit Rows in ANSI SQL and Different RDBMS?

Limiting Rows in ANSI SQL

The MYSQL LIMIT keyword is a convenient way to limit the number of rows returned from a query. However, it is not a standard ANSI SQL syntax. For other RDBMS, there are several alternative ways to achieve row limiting.

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;

Oracle:

SELECT * FROM (SELECT * FROM table) WHERE rownum <= 10;

Conclusion:

Although the MYSQL LIMIT keyword is not an ANSI SQL standard, there are various alternative ways to limit rows in different database systems. The specific syntax may vary depending on the RDBMS being used.

The above is the detailed content of How to Limit Rows in ANSI SQL and Different RDBMS?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn