Reputation: 547
I have a random number - like 10 - and I need to get the 10th register of a recordset.
I do a LOOP with count + 1 until 10.
but if the random number is really big, maybe I need to do a big loop too.
There is an easy method - in performance - to get this record?
NAME | GROUP
Alan A
Paul B
John A
Frank A
SELECT * FROM TABLE WHERE GROUP = A
Randon number is "2" then:
I need to find the 2nd record:
NAME | GROUP
John A
tks daniel
Upvotes: 0
Views: 29
Reputation: 94662
Using LIMIT with an OFFSET you can get just the second row from the resultset
SELECT * FROM TABLE
WHERE GROUP = 'A'
LIMIT 1,1
Except that queries will return data in an order they find easy, so you may want to order the results as well
SELECT * FROM TABLE
WHERE GROUP = 'A'
ORDER BY NAME
LIMIT 1,1
Upvotes: 1