mysql与oracle分页查询

mysql分页查询:

1. SELECT ... FROM ... WHERE ... ORDER BY... LIMIT ...

         例:SELECT *FROM articles WHERE category_id = 123 ORDER BY id LIMIT 50, 10

 

2.通过子查询的方式来提高分页效率

         例:SELECT *FROM articles WHERE  id >= 

 (SELECT id FROM articles  WHERE category_id = 123 ORDER BY id LIMIT10000, 1) LIMIT 10

          

3.JOIN分页方式:

         例:SELECT *FROM content AS t1  

         JOIN(SELECT id FROM content ORDER BY id desc LIMIT".($page-1)*$pagesize.", 1) AS t2  

         WHEREt1.id <= t2.id ORDER BY t1.id desc LIMIT $pagesize;

        

Oracle分页查询语句:

1.从数据库表中第M条记录开始检索N条记录

 SELECT * FROM (SELECT ROWNUM r,t1.* From 表名称 t1 where rownum< M + N) t2    where t2.r >= M  

  例:从表Sys_option(主键为sys_id)中从第10条记录开始检索20条记录

 SELECT * FROM (SELECT ROWNUM R,t1.* From Sys_option where rownum < 30) t2   Where t2.R >= 10

你可能感兴趣的:(sql语句,mysql分页查询,oracle分页查询)