MySQL Forums
Forum List  »  Newbie

Paging, limit, offset, page record count, total record count efficiency
Posted by: Chris Barnes
Date: November 23, 2023 04:15AM

Is there any way that this query could return the number of rows for the whole query as well as for the page ?

SELECT a,b,c FROM d WHERE c='blaa' LIMIT 100,10;

At the moment, I'm having to run the query twice, once to get the total row count:

1) SELECT COUNT(*) FROM (SELECT a,b,c FROM d WHERE c='blaa');

Then

2) SELECT a,b,c FROM d WHERE c='blaa' LIMIT 100,10

Surely there's got to be a more efficient way of doing this ?
Surely, under the bonnet, query number 2 is actually having to take a slice of the whole set, so it already knows the total record count in there ?
But I'm probably just being a naive newb ? ;-)

Many thanks

Options: ReplyQuote


Subject
Written By
Posted
Paging, limit, offset, page record count, total record count efficiency
November 23, 2023 04:15AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.