We help IT Professionals succeed at work.

SQL - Select 2nd unit only in a set of data

208 Views
Last Modified: 2010-05-18
I have a set of data with six records and I need to write a querie that will return only the 2nd record.  I know that I can write something like 'SELECT TOP (2)' and it will only return the first 2 records in the set of data, but is there any way to select the second record only, or the third record only?
Comment
Watch Question

CERTIFIED EXPERT
Awarded 2008
Awarded 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Awarded 2008
Awarded 2008

Commented:
use somefieldname to designate the order in which you want your rows returned...it will ultimately decide what is your "2nd" row or "3rd" row, etc.
Guy Hengel [angelIII / a3]Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009

Commented:
you can do this:
select * 
from ( select top (x)  t.*, row_number() over (order by <some ordering condition here> ) r
         from yourtable t
     ) l
where r = x

Open in new window

Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.