selecting items that come after a specific value

后端 未结 2 1748
臣服心动
臣服心动 2021-01-28 19:00

Say this is my sql:

  SELECT title,
         author,
         ISBN 
    FROM bs_books 
ORDER BY ISBN 
   LIMIT 3

It just selects everything fr

相关标签:
2条回答
  • 2021-01-28 19:07

    You can use OFFSET somenumber to start at a given numeric position. Maybe that's also ok for you?

    If there is a primary key with auto-increment, you can do something like WHERE pk>=somenumber.

    0 讨论(0)
  • 2021-01-28 19:17

    Find the ISBN for the title you want following-ISBNs for, then simply:

    SELECT title, author, ISBN
    FROM bs_books
    WHERE ISBN>'978-3-16-148410-0' -- or whatever ISBN
    ORDER BY ISBN
    LIMIT 3
    

    If you want to select it from just the title in one go, you could use a self-join:

    SELECT b1.title, b1.author, b1.ISBN
    FROM bs_books AS b0
    JOIN bs_books AS b1 ON b1.ISBN>b0.ISDN
    WHERE b0.title='Title for which to get following ISBNs'
    ORDER BY b1.ISBN
    LIMIT 3
    
    0 讨论(0)
提交回复
热议问题