Let say we have data like this.

idtitle
1Vessel, Landmark Baru Manhattan
2Seperti Apa Rasanya Memiliki Rumah “di Bawah” Batu?
3Museum Gempa Di China Berbentuk Menyerupai Retakan Tanah
4Menyusuri Jejak Budaya Peranakan di Rumah Kayu Goen
5Tips Agar Material Semen Ekspos Terlihat Lebih Menarik
6Ciptakan Nuansa Alam Dengan Material Bata Ekspos
7Mengagumi Keindahan Arsitektur Kolonial Istana Cipanas
85 Cara Atasi Masalah Plafon Melendut
9Di dalam Hotel Ini Ada Batu!
10Tips Memilih Papan Gipsum Yang Berkualitas

Now we want to select an item with id 4 and its previous and next item from that order (off course the real order depends on our real query). We can use union to get the current item (id=4), previous item (id=3), and next item (id=5) and the query become like this

sqlite> select * from (select * from table_name where id = 4)
    union
    select * from (select * from table_name where id < 4 order by id desc limit 1)
    union
    select * from (select * from table_name where id > 4 limit 1);

Standard SQL doesn’t permit to use order by and limit in “part” of each union. So we need to filter our query results before calling union select.

The result would be like this.

idtitle
3Museum Gempa Di China Berbentuk Menyerupai Retakan Tanah
4Menyusuri Jejak Budaya Peranakan di Rumah Kayu Goen
5Tips Agar Material Semen Ekspos Terlihat Lebih Menarik