是否有 ANSI SQL 替代 MYSQL LIMIT 关键字?

2021-11-20 00:00:00 database keyword mysql ansi-sql

是否有 ANSI SQL 替代 MYSQL LIMIT 关键字?

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

LIMIT 关键字限制 SELECT 返回的行数,例如:

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

SELECT * FROM People WHERE Age > 18 LIMIT 2;

返回 2 行.

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

返回前 10 行之后的 2 行.

returns 2 rows after the first 10.

推荐答案

this不同的方式:

-- 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

相关文章