Home >Database >Mysql Tutorial >How Can I Limit the Number of Rows Returned in ANSI SQL?

How Can I Limit the Number of Rows Returned in ANSI SQL?

Susan Sarandon
Susan SarandonOriginal
2024-11-25 14:48:15675browse

How Can I Limit the Number of Rows Returned in ANSI SQL?

ANSI SQL Alternatives to the MYSQL LIMIT Keyword

In MySQL, the LIMIT keyword is used to restrict the number of rows returned by a SELECT statement. However, there are alternative ways to achieve this in ANSI SQL, which is supported by other database management systems.

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

Each of these alternative syntaxes can be used to retrieve a specified number of rows from a table, similar to the LIMIT keyword in MySQL. By understanding these alternatives, developers can ensure compatibility with different database systems and write portable SQL queries.

The above is the detailed content of How Can I Limit the Number of Rows Returned in ANSI SQL?. 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