Posted by: SQL_PRO August 27, 2014
SQL Select Statement
Login in to Rate this Post:     0       ?        
Here you go NepaliBhai......................


create table #table1(steps int)
insert into #table1(steps)values(1)
insert into #table1(steps)values(3)
insert into #table1(steps)values(4)
insert into #table1(steps)values(5)

select distinct x.stepFrom, Y.stepTo from
(select rank()over(order by a.steps )as rank,a.steps as stepFrom from (select top 3 * from #table1 order by 1 asc) a
left outer join #table1 b
on a.steps =b.steps) x
inner join
(select rank()over(order by a.steps )as rank,a.steps as stepTo from (select top 3 * from #table1 order by 1 desc) a
left join #table1 b
on a.steps =b.steps) y
on x.rank =y.rank

drop table #table1
Read Full Discussion Thread for this article