The following MySQL query returns a result set with just over a million rows:
SELECT postid
FROM post p
JOIN thread t ON p.threadid = t.threadid
WHERE t.forumid = 10
AND t.visible = 1
AND p.visible = 1
ORDER BY p.dateline desc
Which is nice, however I want to get the row at the millionth position.
So the question is, if you haven’t guessed already, how do I go about doing this
NOTE : This table is actively being used, so new rows are added all the time.
EDIT : That question isn’t entirely clear, the query returns a list of all posts in a specific forum order by post date desc, so it isn’t so much the millionth post in the result set rather the millionth post on the forum.
You can use the LIMIT clause which accepts a zero-based record index followed by a record count.
Therefore for a single record at the millionth row, you could use: