sql pulling a row for next or previous row of a current row

后端 未结 6 1573
抹茶落季
抹茶落季 2020-12-03 05:51
id    |  photo title     |  created_date

XEi43 |  my family       |  2009 08 04
dDls  |  friends group   |  2009 08 05
32kJ  |  beautiful place |  2009 08 06
EOIk  |  wo         


        
6条回答
  •  时光说笑
    2020-12-03 06:25

    Did you want the next/previous row by date? If so, you could do this:

    select MyTable.*
    from MyTable
    join
      (select id
       from MyTable
       where created_date < (select created_date from MyTable where id = '32kJ')
       order by created_date desc, id desc
       limit 1
      ) LimitedTable on LimitedTable.id = MyTable.fund_id;
    

提交回复
热议问题