首頁  >  文章  >  資料庫  >  mysql limit進階用法範例

mysql limit進階用法範例

黄舟
黄舟原創
2017-02-06 15:39:111077瀏覽

mysql limit效率:

select `id`,`title`,`describle`,`created` from myvbga_table where click = xxx limit offset, limit; //总结:如果没有blob/text字段,单行记录比较小,可以把 limit 设大点,会加快速度。

limit offset值比較小:

select `id`,`title`,`describle`,`created` from vbga_table limit 10,10 //多次运行,时间保持在0.0004-0.0005之间
Select `id`,`title`,`describle`,`created` From vbga_table Where click >=(Select click From vbga_table Order By click limit 10,1) limit 10 
//多次运行,时间保持在0.0005-0.0006之间,主要是0.0006

limit offset值比較大:

select `id`,`title`,`describle`,`created` from vbga_table limit 10000,10 //多次运行,时间保持在0.0187左右
Select `id`,`title`,`describle`,`created` From vbga_table Where click >=(Select click From vbga_table Order By click limit 10000,1) limit 10

//多次運行,時間保持在0.0061左右,只有前者的1/3。可以預期offset越大,後者越優。

Mysql的limit用法:

LIMIT 子句可以被用來強制SELECT 陳述式傳回指定的記錄數

SELECT `id`,`title`,`describle`,`created` FROM vbga_table LIMIT [offset,] rows | rows OFFSET offset
mysql> SELECT `id`,`title`,`describle`,`created` FROM vbga_table LIMIT 5,10; // 检索记录行 6-15 //为了检索从某一个偏移量到记录集的结束所有的记录行,
可以指定第二个参数为 -1:
mysql> SELECT `id`,`title`,`describle`,`created` FROM vbga_table LIMIT 95,-1; // 检索记录行 96-last. //如果只给定一个参数,它表示返回最大的记录行数目:
mysql> SELECT `id`,`title`,`describle`,`created` FROM vbga_table LIMIT 5; //检索前 5 个记录行 //换句话说,LIMIT n 等价于 LIMIT 0,n。


mysql limit 子查詢用法範例:


mysql limit 子查詢用法範例: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~


SELECT `keyword` FROM `zjoe_table` WHERE advertiserid='59' ORDER BY keyword LIMIT 2 ,1; //而這個SQL,limit後面是從第2條開始讀,讀取1條訊息。


mysql存儲過程中limit變數用法

select `id`,`title`,`describle`,`created` from vbga_table where id in (select t.id from (select `id`,`title`,`describle`,`created` from vbga_table limit 10)as t)


注意:需要傳參數的地方一定要用"?"號,第一個FRom後面的語句要用''括起。

以上就是mysql,limit,高級用法的內容,更多相關內容請關注PHP中文網(www.php.cn)!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn