태터데스크 관리자

도움말
닫기
적용하기   첫페이지 만들기

태터데스크 메시지

저장하였습니다.

============ Oracle ==========

ORDER BY 조건에 유니크한 값을 추가해 주어야 합니다.

pstmt = conn.prepareStatement(
 "select *  from  (select a.*, rownum rnum  from (select *  from board  order
 by num desc, pos asc) a  where rownum <= ? ) where rnum >= ?
 ");
            pstmt.setInt(1, end);
            pstmt.setInt(2, start);
            rs = pstmt.executeQuery();





============ MySQL ==========

limit 10   -----> 처음부터 10개를 리턴
limit 1,10 -----> 2번째부터 10개를 리턴
limit 1,-1 -----> 2번째부터 마지막까지를 리턴

pstmt = conn.prepareStatement(
                 "select * from board order by num desc, pos asc limit ?,? ");
            pstmt.setInt(1, start-1);
            pstmt.setInt(2, end);
            rs = pstmt.executeQuery();





============ MySQL 페이징 ==========

limit 사용하여 페이징을 할려면 쿼리를 두번을 해야한다.

1. 해당 조건을 만족하는 게시물의 전체 수를 가져오는 쿼리
2. 그 페이지에서 보여줄 필드를 가져오는 쿼리

쿼리를 쉽게 해주는 function을 MySQL 은 제공한다.

첫번째 쿼리로 10 rows의 데이터가 리턴됨
두번째 쿼리로 where절을 만족하는 개수가 리턴됨

mysql> SELECT SQL_CALC_FOUND_ROWS * FROM board
mysql> 
WHERE  num  > 100 LIMIT 10;

mysql>
SELECT FOUND_ROWS();





top

Trackback Address :: http://www.ssial.com/trackback/31 관련글 쓰기

  1. Chanel Outlet 2011/09/17 21:41 댓글주소 | 수정/삭제 | 댓글

    Time is what you make of it.

  2. Burberry Bags 2011/10/13 17:10 댓글주소 | 수정/삭제 | 댓글

    I'm happy I found this blog! From time to time students want to cognitive the keys of productive literary essays composing. Your first-class knowledge about this good post can become a proper basis for such people. Thanks.

  3. Coach Outlet Online 2011/11/15 12:52 댓글주소 | 수정/삭제 | 댓글

    I'm happy I found this blog ! It's very good and thank you for sharing it !

Write a comment