Home >Database >Mysql Tutorial >LIMIT and OFFSET in SQLite: What's the Difference Between `LIMIT 100 OFFSET 50` and `LIMIT 100, 50`?
Understand the usage of LIMIT and OFFSET in SQLite
This article explains the difference between LIMIT and OFFSET in SQLite queries.
Question:
Please differentiate between the following two SQLite queries:
<code class="language-sql">SELECT * FROM Animals LIMIT 100 OFFSET 50</code>
and
<code class="language-sql">SELECT * FROM Animals LIMIT 100, 50</code>
Answer:
The two syntaxes are equivalent, except that the order of numbers is reversed:
LIMIT <跳过>, <数量>
is equivalent to LIMIT <数量> OFFSET <跳过>
SQLite supports both syntaxes, but it is recommended to use the latter to avoid confusion. This is similar to the syntax used in MySQL and PostgreSQL, although MySQL also supports both forms.
Be aware that using ORDER BY
without specifying LIMIT
may lead to unexpected results. The order of rows returned will be determined by physical storage, which may not be consistent with the expected arrangement. To ensure predictable ordering, it is recommended to use ORDER BY
explicitly.
The above is the detailed content of LIMIT and OFFSET in SQLite: What's the Difference Between `LIMIT 100 OFFSET 50` and `LIMIT 100, 50`?. For more information, please follow other related articles on the PHP Chinese website!