Reputation: 73305
In the following query:
SELECT column1,column2 FROM table1 ORDER BY column1 LIMIT 0,30
How can I find out the number of rows that would have been returned were it not for the LIMIT
?
Edit: I am looking for a way to work this into the query above and not do a separate query. (If possible.)
Upvotes: 1
Views: 253
Reputation: 229342
If you do this query:
SELECT SQL_CALC_FOUND_ROWS column1,column2 FROM table1 ORDER BY column1 LIMIT 0,30;
You can retrieve the number of rows the previous SELECT found with
select FOUND_ROWS();
If you really must do it with one query, you'll have to use a sub select (which'll have the disatvantage of adding an extra column to every row..)
SELECT column1,column2,s.total FROM table1,
(select count(*) as total from table1) s
ORDER BY column1 LIMIT 0,30;
Upvotes: 0