Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get 2nd row (not 1st) from result set 1

Status
Not open for further replies.

vnad

MIS
Nov 22, 2002
91
US
I would like to return the second row of a result set to compare against. I am currently using TOP 1 but I do not want that row that is returned.

Here is my code.

select * from uTable where sField = (select TOP 1 sField from utable where sAccount = '12345')

I would like to get the second row it returns and not the first. Is there a bottom command? Thanks,

Dan
 
I think this will work:

select Top 1
ut1.*
from
utable ut1
where ut1.sField in (select ut2.sField from utable ut2 where ut2.sAccount = '12345' and not ut2.sField = (select TOP 1 ut3.sField from utable ut3 where ut3.sAccount = '12345'))
 
This is a bit simpler, and avoids the use of IN

Code:
select top 1 * 
from (select top 2 *  from utable
 order by sField asc) as t1
order by sField desc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top