snippetsqlMinor
How to COUNT number of rows with LIMIT?
Viewed 0 times
rowsnumberwithlimithowcount
Problem
I want to catch X rows, thus, I set
Currently, I use two separate queries to do so as
Is there a way to do this in one query?
EDIT: The output should be the
I know that it is not possible to merge these two queries, as the first return 1 row, but the second X rows. I am curious if there is a function in mysql to return the number of rows in the presence of
LIMIT X; but how can I simultaneously count the total number of rows too?Currently, I use two separate queries to do so as
SELECT COUNT(*) FROM col WHERE CLAUSE
SELECT * FROM col WHERE CLAUSE LIMIT XIs there a way to do this in one query?
EDIT: The output should be the
col cells and the number of rows. In fact, after selecting the col cells, it should walk over the table to count only.I know that it is not possible to merge these two queries, as the first return 1 row, but the second X rows. I am curious if there is a function in mysql to return the number of rows in the presence of
LIMIT.Solution
It sounds like you want to run the LIMIT, but still know how many rows would have been returned without the LIMIT. Check out FOUND ROWS
Context
StackExchange Database Administrators Q#28218, answer score: 8
Revisions (0)
No revisions yet.