mysql found row_mysql found_row()使用详解
mysql 4.1中新增了FOUND_ROWS()函數,這個函數的說明是這樣的:
For a SELECT with a LIMIT clause, the number of rows that would be returned were there no LIMIT clause
A SELECT statement may include a LIMIT clause to restrict the number of rows the server returns to the client. In some cases, it is desirable to know how many rows the statement would have returned without the LIMIT, but without running the statement again. To obtain this row count, include a SQL_CALC_FOUND_ROWS option in the SELECT statement, and then invoke FOUND_ROWS() afterward:
比如說有段sql需要取出一張表的前10行,同時又需要取出符合條件的總數。這在某些分頁操作中很常見
SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name
WHERE id > 100 LIMIT 10;
在上一查詢之后,你只需要用FOUND_ROWS()就能獲得查詢總數,這個數目是拋掉了LIMIT之后的結果數:
SELECT FOUND_ROWS();
其中第一個sql里面的SQL_CALC_FOUND_ROWS不可省略,它表示需要取得結果數,也是后面使用FOUND_ROWS()函數的鋪墊。
記一次使用中遇到的問題的解決方法
寫MySQL分頁使用了發現FOUND_ROWS總是返回1,實際記錄絕不止1條。SQL語句如下:
select sql_calc_found_rows * from actionlist where A_ID > 0 limit 10;
select FOUND_ROWS();
網上查找中文資料,沒有解決。英文資料找到問題原因
使用MySQL Workbech出現了上述問題。使用MySQL Command Line Client執行同樣SQL語句返回值OK!
要是遇到同樣問題,試試!
總結
以上是生活随笔為你收集整理的mysql found row_mysql found_row()使用详解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PSO-LSSVM算法及其MATLAB代
- 下一篇: python中range 函数_Pyth