I have a table 'Labs' with 14 entries.
The query SELECT COUNT(Labs.sid) FROM Labs LIMIT 0, 18446744073709551615 returns "14".
However the query SELECT COUNT(Labs.sid) FROM Labs LIMIT 1, 18446744073709551615 returns "0" (not 13 as I would expect). In fact, "0" is still returned when I set the LIMIT row offset value 2, 3, 4, etc.
Why is this? Is there a way to determine the number of rows after a specified offset using just mysql?
FWIW I'm using MySQL 5.5.9 and the InnoDB database engine.
解决方案
The limit is applied AFTER the count is performed.
Try this instead:
SELECT COUNT(sid) FROM
(
SELECT sid FROM Labs LIMIT 2, 18446744073709551615
) T1
Note that it is a bad idea to use LIMIT without an ORDER BY because you can't guarantee that the order will be consistent so different rows could in theory be selected each time (which matters if sid can be NULL).