Hello,friends!

          loocao

          myJavaWorld

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            13 Posts :: 0 Stories :: 0 Comments :: 0 Trackbacks

          用mysql的limit進行分頁。。發現竟然有些數據沒顯示在頁面上。。總共才24條數據。楞找不到。。
          后來把語句弄到mysql上查了一下才知道。這條語句中的limit有問題。。有些數據在第二頁被重復顯示了。。
          非常郁悶。。下面給截圖
          查第一頁的語句

          SQL code
                      
          SELECT * FROM article a where a.type in (1,2,4) limit 0,20;

          第一頁的結果
          (注意紅色部分)
          第二頁的語句

          SQL code
                      
          SELECT * FROM article a where a.type in (1,2,4) limit 20,20;

          結果:
          (注意紅色部分)
          --------------------------------------------------------------------------
          后來發現排下序就沒事了。。原來用MySQL的limit必須排序。。唉
          這是一位網友給的MySQL Help:
          If you use LIMIT row_count with ORDER BY, MySQL ends the sorting as soon as it has found the first row_count rows of the sorted result, rather than sorting the entire result. If ordering is done by using an index, this is very fast. If a filesort must be done, all rows that match the query without the LIMIT clause must be selected, and most or all of them must be sorted, before it can be ascertained that the first row_count rows have been found. In either case, after the initial rows have been found, there is no need to sort any remainder of the result set, and MySQL does not do so.
          ..用limit必須排序,,切記切記...


          phyeas 2008-07-18 17:54 發表評論

          文章來源:http://www.aygfsteel.com/phyeas/archive/2008/07/18/215874.html
          posted on 2008-07-18 17:54 loocao 閱讀(2843) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 崇左市| 松阳县| 阿荣旗| 青铜峡市| 施甸县| 台东市| 利津县| 巩留县| 娄烦县| 正阳县| 临沭县| 江津市| 清远市| 桃江县| 海阳市| 沛县| 女性| 保山市| 六枝特区| 盐亭县| 邵东县| 土默特左旗| 开原市| 达尔| 井冈山市| 新巴尔虎右旗| 灵石县| 岑溪市| 房产| 蒙城县| 新和县| 上高县| 沙雅县| 娄烦县| 九江县| 新密市| 永德县| 西安市| 格尔木市| 高雄县| 闻喜县|