select * from tablename a where id = (select max(id) from tablename where id < a.id) or id = (select min(id) from tablename where id > a.id)
SELECT * FROM table1 WHERE id-123 BETWEEN -2 AND 2
(select max(id) from tablename a where a.id<123) union all (select min(id) from tablename a where a.id>123)
create table T(id int) insert T select 111 union all select 123 union all select 124 union all select 125select id=max(id) from T where id<123 union all select id from T where id=123 union all select min(id) from T where id>123
select top 1 id from tablename where id < 123 order by id DESC select top 1 id from tablename where id > 123 order by id ASC
where id = (select max(id) from tablename where id < a.id)
or id = (select min(id) from tablename where id > a.id)
FROM table1
WHERE id-123 BETWEEN -2 AND 2
union all
(select min(id) from tablename a where a.id>123)
insert T select 111
union all select 123
union all select 124
union all select 125select id=max(id) from T where id<123
union all
select id from T where id=123
union all
select min(id) from T where id>123
select top 1 id from tablename where id > 123 order by id ASC