August 3, 2008 at 11:16 pm
Hi,
is it possible to select nth row of a table?
like
column1 column2 column3
a value0 xxxxx
c value1 xxxxx
f value2 xxxxx
d value3 xxxxx
x value4 xxxxx
i want to retrive ; f value2 xxxxx
condition is, i'm not aware of the values so i cant use where clause or any conditions. but i simply want to retrive row 3.
is that possible?
August 4, 2008 at 12:55 am
Of course you can:
SELECT *
FROM (
SELECT *, ROW_NUMBER() OVER (ORDER BY Column1) AS ROW_NUM
FROM MyTable
) AS Data
WHERE ROW_NUM = @The_Row_You_Want
This works only in SQL2005, anyway.
Hope this helps,
Gianluca
-- Gianluca Sartori
August 4, 2008 at 1:03 am
i should have mention it.. but i work with MS SQL 2000..;p
thanks for reply gianluca
August 4, 2008 at 1:17 am
Ok, so, let's convert it into SQL2000 syntax:
SELECT TOP 1 *
FROM (
SELECT TOP The_Row_You_Want *
FROM MyTable AS A
ORDER BY Column1 ASC
) AS DATA
ORDER BY Column1 DESC
There are many other ways to achieve it, this is only a hint.
Regards,
Gianluca
-- Gianluca Sartori
August 4, 2008 at 2:41 am
Astig!!:D (great in english..;p)
lots of thanks gianluca.. now im learning..;p
August 4, 2008 at 3:18 am
Sobrang tuwa ahhh 😀
"-=Still Learning=-"
Lester Policarpio
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply