By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table table1(id int);
insert into table1 values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
(select *
from table1
where id <= 2
order by id desc
limit 5)
union all
(select *
from table1
order by id desc
limit 5)
limit 5
id |
---|
2 |
1 |
10 |
9 |
8 |
(select *
from table1
where id <= 9
order by id desc
limit 5)
union all
(select *
from table1
order by id desc
limit 5)
limit 5
id |
---|
9 |
8 |
7 |
6 |
5 |