开发者

selecting items that come after a specific value

开发者 https://www.devze.com 2023-01-23 01:48 出处:网络
Say this is my sql: SELECT title, author, ISBN FROM bs_books ORDER BY ISBN LIMIT 3 It just selects everything from a certain table (title, author, etc..).

Say this is my sql:

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

It just selects everything from a certain table (title, author, etc..).

Say I would like to开发者_JS百科 select all the items that come after a certain title, not alphabetically or something but just the records after the certain element. How would I approach this?


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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号