Mysql
 sql >> Database >  >> RDS >> Mysql

Come ottenere il numero di risultati totali quando nella query è presente LIMIT?

Aggiungi una colonna, total , ad esempio:

select t.*
     , (select count(*) from tbl where col = t.col) as total
from tbl t
where t.col = 'anything'
limit 5

Come affermato da @Tim Biegeleisen :limit la parola chiave viene applicata dopo tutto il resto, quindi count(*) restituisce comunque la risposta giusta.