How to count all rows when using SELECT with LIMIT in MySQL query?

前端 未结 5 1405
一整个雨季
一整个雨季 2020-11-27 05:47

I\'ve got a mysql query like this:

SELECT A.ID, A.NAME, B.ID, B.NAME
FROM table1 A
JOIN table2 B ON ( A.ID = B.TABLE1_ID )
WHERE
    cond1, cond2, ..., condN         


        
5条回答
  •  生来不讨喜
    2020-11-27 06:26

    You can use the SQL_CALC_FOUND_ROWS with FOUND_ROWS() to count the number of results while that query is executing. Basically you just add 'SQL_CALC_FOUND_ROWS' after 'SELECT' and then run another query 'SELECT FOUND_ROWS()' after that. It is not possible to send back the count in the same query because it cannot know the count until the query is finished.

提交回复
热议问题