tags:

views:

29

answers:

1

if I run a SELECT query that returns 10 rows, is there a way to select the 2nd item in the result set right in the SELECT statement (effectively getting a single row result)?

psedudo code:

SELECT id from MYTABLE where MYTABLE.foo = 0 and RESULT_INDEX = 2;

this would return the 2nd item from a multi item result set.

+2  A: 
SELECT id from MYTABLE where MYTABLE.foo = 0 LIMIT 1, 1;

You'll probably want to specify an ORDER BY clause or else the nth result will be arbitrarily defined.

Edit: Oops, the first LIMIT param is zero based

Phil Brown
I played with this, but it didn't produce the desired result, exactly. If I limit 1 then I'll only get the first result, which isn't what I'm after. I want the result set to be as many as it would organically be, but then to pluck the item from a specific location in that result set. I'm doing it programmatic now, but was hoping there was a straight sql approach.
Dr.Dredel
Did you use `LIMIT 1, 1`? This retrieves one record at offset 1 (second row) from the resultset. This sounds exactly like what you're after but I may be interpreting your question incorrectly.
Phil Brown
no, I had followed your initial instructions, this works, thanks!
Dr.Dredel