Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

only want one result

select column from table order by column desc

I only want the fifth result
ASKER CERTIFIED SOLUTION
Avatar of Jason Schlueter
Jason Schlueter
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can give the row_number and select the 5th row.

; With CTE as
            (
                  select column1, column2,...., columnN,
                  RN = ROW_NUMBER() OVER (PARTITION BY NULL ORDER BY requiredColumn DESC)
            )
select * from CTE
where RN = 5
Avatar of Jim Horn
If you mean fifth result as the fifth row returned, with no special ordering, then...

SELECT column
FROM (
      select column, row_number() OVER (ORDER BY (SELECT 0)) as row_number
      FROM table) a
WHERE a.row_number = 5

If there is any special ordering, then replace the SELECT 0 part with however you wish to order.
Or,

select
      top 5 *
into #temp_tbl
from YourTable
order by column desc


select top 1 * from #temp_tbl order by column
select top 1 z.column
from (select top 5 column from table order by column desc) z
order by z.column
Avatar of rgb192

ASKER

thank you for quick answer