Skip to content

Getting Count for Query with Filters, Order etc. #177

Answered by stephenafamo
trentassaya asked this question in Q&A
Discussion options

You must be logged in to vote

I have considered removing the Count method since it may not work how you would expect.

What Count does is overwrite any selected columns with SELECT COUNT(1) and add .... LIMIT 1 before making the query. And since this modifies the original query, it can lead to unexpected issues like this.

One solution would be to clone the query before issuing a Count that way the original query is not modified at all. We could then do other things like drop the ORDER BY which would have no effect on such a query anyway.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@trentassaya
Comment options

Answer selected by stephenafamo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants