开发者

Check for previous and next entry in SQLITE

开发者 https://www.devze.com 2023-02-15 00:06 出处:网络
I have an android application that uses a sqlite database. M开发者_如何学Goy app has a next and previous button to view entries in the database. I need to check whether or not a next or previous entry

I have an android application that uses a sqlite database. M开发者_如何学Goy app has a next and previous button to view entries in the database. I need to check whether or not a next or previous entry exists that way i can disable the button if one does not exist.


Run a query to get the IDs of each record in the table and cache this. Then you know if there are next or previous entries. Click the button, and your app would do a primary key lookup based on the cached data.


Try something like this:

SELECT *,
(SELECT id FROM my_table WHERE id < <my_id> ORDER BY id DESC LIMIT 1) AS previous_id,
(SELECT id FROM my_table WHERE id > <my_id> ORDER BY id ASC LIMIT 1) AS next_id
FROM my_table WHERE a = <my_id>
0

精彩评论

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