Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Select 2nd row from a table

Author  Topic 

DLTaylor
Posting Yak Master

136 Posts

Posted - 2006-11-07 : 13:04:20

I have received a very strange request where I need to write a select statement that returns the 2nd row in a table.
I though this would be easy but cant find a way to return the 2nd row.

The basic;

Select Top 2*
From tablename

Returns rows 1 and 2 but I would like to return only the second row.
Note: there is never a set criteria in the 2nd row.

any ideas would be much appreciated.
Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-07 : 13:06:24
select top 1 * from (select top 2 * from tablename order by somecolumn) q order by somecolumn desc


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -