Optimizing queries for the next and previous element

前端 未结 11 911
耶瑟儿~
耶瑟儿~ 2021-01-30 11:33

I am looking for the best way to retrieve the next and previous records of a record without running a full query. I have a fully implemented solution in place, and would like to

11条回答
  •  鱼传尺愫
    2021-01-30 11:42

    So you have two tasks:

    1. build sorted list of items (SELECTs with different ORDER BY)
    2. show details about each item (SELECT details from database with possible caching).

    What is the problem?

    PS: if ordered list may be too big you just need PAGER functionality implemented. There could be different implementations, e.g. you may wish to add "LIMIT 5" into query and provide "Show next 5" button. When this button is pressed, condition like "WHERE price < 0.89 LIMIT 5" is added.

提交回复
热议问题