テーブルの最後の 2 行を 1 回のクエリで新しいデータと前のデータとして取得したい
私は得た
select tbl.x , tbl2.x as last_x
from tbl left join tbl tbl2 ON tbl.id!= tbl2.id
order by tbl.id desc , tbl2.id desc limit 1
正常に動作しますが、大きなDBでは遅くなる可能性があると思います
これをより速くする方法はありますか?
テーブルの最後の 2 行を 1 回のクエリで新しいデータと前のデータとして取得したい
私は得た
select tbl.x , tbl2.x as last_x
from tbl left join tbl tbl2 ON tbl.id!= tbl2.id
order by tbl.id desc , tbl2.id desc limit 1
正常に動作しますが、大きなDBでは遅くなる可能性があると思います
これをより速くする方法はありますか?