Find the adjacent data of a data (previous, next)

premise:

  1. Tested with MySql 5.6.
  2. The primary key ID of this table uses an auto-growth strategy.

(SELECT * FROM survey.t_zwgk_lmnr where id > 5 limit 1) union 

(SELECT * FROM survey.t_zwgk_lmnr where id < 5 order by id desc limit 1);

 

Note that parentheses must be added, otherwise the search result will be wrong.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326383239&siteId=291194637