SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member hamedghaderi's Avatar
    Join Date
    Dec 2012
    Location
    Sanandaj, Kurdestan, Iran
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using LIMIT in SELECT statement

    I have a table with 37 posts and now I want to select every 10 post per page
    Is there any approach to limit items between interval numbers?
    exp:
    Code:
    SELECT name FROM posts LIMIT(10-20)

  2. #2
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,176
    Mentioned
    63 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by hamedghaderi View Post
    I have a table with 37 posts and now I want to select every 10 post per page
    Is there any approach to limit items between interval numbers?
    exp:
    Code:
    SELECT name FROM posts LIMIT(10-20)
    What your referring to is pagination I believe.
    LIMIT 10 will return 10 records, when using a second argument, LIMIT 0,10 for example, will return 10 records, starting at row 0. The first argument will become your variable depending on what page you are on. For page two, you would use LIMIT 10,10, page three LIMIT 20, 10.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,215
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by K. Wolfe View Post
    LIMIT 0,10 for example, will return 10 records, starting at row 0.
    "starting at row 0" isn't quite right

    it's actually an offset, which i prefer to describe as "the number of rows to skip over"

    so LIMIT 20,10 doesn't start at row 20, it skips over 20 rows
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •