Databases Reporting with SQL Ordering, Limiting and Paging Results Review: Ordering, Limiting and Paging Results

Reporting with SQL final assesment: i am thrown off by: LIMIT 0, OFFSET 50. should any rows be returned at all?

To me it seems like this query would return 0 results based on LIMIT = 0, regardless of the OFFSET

2 Answers

54,287 Points

If you are referring to this question:

Can you guess what the following query would do?

SELECT * FROM passport_holders WHERE name = "Lauren" LIMIT 0, 50;

The limit and offset when specified by values separated by a comma are reversed. Here the limit is 50 and the offset is 0. You can read about it in the SQLite documentation

Instead of a separate OFFSET clause, the LIMIT clause may specify two scalar expressions separated by a comma. In this case, the first expression is used as the OFFSET expression and the second as the LIMIT expression. This is counter-intuitive, as when using the OFFSET clause the second of the two expressions is the OFFSET and the first the LIMIT. This reversal of the offset and limit is intentional - it maximizes compatibility with other SQL database systems. However, to avoid confusion, programmers are strongly encouraged to use the form of the LIMIT clause that uses the "OFFSET" keyword and avoid using a LIMIT clause with a comma-separated offset.

thanks, Kris Nikolaisen.