+ 1

SQL order

SELECT ID, Name, City FROM customers OFFSET 3 LIMIT 4; SELECT ID, Name, City FROM customers LIMIT 4 OFFSET 3 Are the two statements equivalent in SQL.

29th Jan 2022, 4:05 PM
Hein Htet Naing
3 Réponses
+ 5
Yes
29th Jan 2022, 4:59 PM
Simba
Simba - avatar
+ 1
OFFSET and LIMIT are not standard SQL clauses, they are specific to database engine, for example MySQL and PostgreSQL. For specific rules of usage, you should check the reference manual, but in my understanding, in these two dialects, LIMIT should come first. Also it is important to use a deterministic ORDER BY clause with offset. Otherwise you can get inconsistent result, because the SQL engine might choose internally a different query plan to execute for different offsets. https://dev.mysql.com/doc/refman/8.0/en/select.html https://www.postgresql.org/docs/current/queries-limit.html Other dialects use other patterns MS SQL Server: SELECT TOP X Oracle SQL: SELECT ... OFFSET X FETCH FIRST Y ROWS
30th Jan 2022, 6:26 AM
Tibor Santa
Tibor Santa - avatar
0
SELECT ID, Name, City FROM customers OFFSET 3 LIMIT 4; SELECT ID, Name, City FROM customers LIMIT 4,3; Then, do they make the same result? Is there any difference? Can we use without OFFSET keyword? Thank You
30th Jan 2022, 3:11 AM
Hein Htet Naing