mysql found_row()應用詳解。本站提示廣大學習愛好者:(mysql found_row()應用詳解)文章只能為提供參考,不一定能成為您想要的結果。以下是mysql found_row()應用詳解正文
mysql found_row()用於獲得Select獲得的行數,好比有段sql須要掏出一張表的前10行,同時又須要掏出相符前提的總數。 本文章向年夜家引見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!
如果碰到異樣成績,嘗嘗!