rgb192
asked on
only want one result
select column from table order by column desc
I only want the fifth result
I only want the fifth result
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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 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
from (select top 5 column from table order by column desc) z
order by z.column
ASKER
thank you for quick answer
; With CTE as
(
select column1, column2,...., columnN,
RN = ROW_NUMBER() OVER (PARTITION BY NULL ORDER BY requiredColumn DESC)
)
select * from CTE
where RN = 5