How to COUNT number of rows with LIMIT?
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
I know this is an old one but it is not valid anymore, with MySQL >= 8.0.17
cf MySQL Function Found_Rows()
So we still have to issue both queries ie. add one with the COUNT()
, unfortunately.
Use SQL_CALC_FOUND_ROWS
in your SELECT query and then run SELECT FOUND_ROWS()
:
SELECT SQL_CALC_FOUND_ROWS field_name,filed_name2 FROM col WHERE CLAUSE LIMIT X;
SELECT FOUND_ROWS() ;