Home >Database >Mysql Tutorial >How to Retrieve the Nth Row from a Database Table Regardless of the DBMS?
Overview
Accessing a particular database table row by its position is a frequent task. Although individual database systems (DBMS) provide their own methods, several approaches work across different database platforms.
Cross-DBMS Techniques
OFFSET-LIMIT Clause:
SELECT ... LIMIT y OFFSET x
Window Functions:
<code class="language-sql"> SELECT * FROM ( SELECT ROW_NUMBER() OVER (ORDER BY key ASC) AS rownumber, columns FROM tablename ) AS foo WHERE rownumber = n</code>
DBMS-Specific Solutions
SQL Server: The window function approach (as described above) is applicable.
MySQL: The OFFSET-LIMIT
clause (as described above) is the preferred method.
PostgreSQL: Both the OFFSET-LIMIT
clause and window functions (for versions 8.4 and later) are suitable.
SQLite: Support for both OFFSET-LIMIT
and window functions is available in version 3.25.0 and later.
Oracle: The window function method (as detailed previously) is the standard approach.
The above is the detailed content of How to Retrieve the Nth Row from a Database Table Regardless of the DBMS?. For more information, please follow other related articles on the PHP Chinese website!