Silly MYSQL limit examples

This is a common example for mysql limits. I think it is even in the official documentation (which is repeated all over the net).

SELECT * FROM `your_table` LIMIT 5, 5

This will show records 6, 7, 8, 9, and 10

Why silly? Because is it the first 5 or the second 5 that is the place you start, and is it the first five or the second five that is the number of rows to show? Yes, I know the answer, but for newbies they just stare and this and say ‘great, but why’. An example of that would be better would be:

SELECT * FROM `your_table` LIMIT 15, 4

This will show records 16, 17, 18, 19.

This gives a user a chance to think backward, apply a little math if the direct explanation is not present. Sometimes the guys who write these manuals aren’t thinking like a person who actually needs the manual for help.

]]>