1. 程式人生 > >My Sql 高效分頁

My Sql 高效分頁

/*
 *普通分頁
 *在資料檔案上偏移1000000查出10條
 */

select *
from zoldesk_92game_net_ecms_bj
where classid=303
ORDER BY id ASC
LIMIT 1000000,10 ;

/*
 *高效分頁
 *1、在索引上查出起始索引
 *2、從起始索引上查出10條
 */

SELECT * from zoldesk_92game_net_ecms_bj WHERE id >=
(
    SELECT id
    FROM zoldesk_92game_net_ecms_bj
    where classid=303
    ORDER BY id ASC
    LIMIT 1000000, 1
)
and classid=303
ORDER BY id ASC
LIMIT 10 ;

這是樓下的辦法

SELECT * from zoldesk_92game_net_ecms_bj WHERE id in    
(    
    SELECT id from 
    (
        SELECT id    
        FROM zoldesk_92game_net_ecms_bj    
        where classid=303    
        ORDER BY id ASC    
        LIMIT 1000000, 10    
    )
    AS temp
)