Differences in the scripts of "queries the first few rows to the fewest rows" in different databases

mysql database:

  ① SELECT * FROM table LIMIT [offset,] rows | rows OFFSET offset;

  ② SELECT * FROM table ORDER BY id LIMIT [offset,] rows | rows OFFSET offset;

pgsql database:

  ① SELECT * FROM table LIMIT 10 OFFSET 20;

  ② SELECT * FROM table ORDER BY id LIMIT 10 OFFSET 20;

mssql database:

  ① SELECT TOP 10 * FROM table WHERE id in (SELECT TOP 20 id FROM table ORDER BY id) ORDER BY id DESC;

  ② SELECT IDENTITY(int,1,1) id,* INTO temp FROM table;SELECT * FROM temp id BETWEEN 10 AND 20;

oracle database:

  ① SELECT * FROM table WHERE rownum < 20 

    minus 

    SELECT * FROM table WHERE rownum < 10;

  ② SELECT * FROM (SELECT t.*, row_number() over(ORDER BY id)rowid FROM table t) WHERE rowid BETWEEN 10 AND 20;

Guess you like

Origin www.cnblogs.com/az4215/p/12689826.html