0

I wish to fetch all rows from table after the nth Position as i given offset value my table like

id | Value
1  | A |
2  | B |
3  | C |
4  | D |
5  | E |

...

N  | R |

I wants the 3rd row Data to Nth Rows How to i Retrive

  • @akina how to i fix this – sivag Feb 29 at 7:22
  • What version of mysql? – Lennart Feb 29 at 8:49
  • @Lennart Mysql 5.0 and above – sivag Feb 29 at 9:21
  • 8 is a lot more powerfull than 5, but then the solution must work for 5? – Lennart Feb 29 at 9:30
  • @Lennart yes i know that but live server codes are maintained version 5 standard so i'm unable to update the server version right now – sivag Feb 29 at 9:46
0

Disclaimer, the oldest version I could test was 5.6

select t1.id, t1.val 
from t t1
left join (
   select t2.id from t t2 order by id limit 2
) x
on t1.id = x.id
where x.id is null;

For 8.0, a window function is the most natural choice

select id, val from (
  select id, val
     , row_number() over (order by id) as rn
  from t
) as x 
where rn > 2

As ypercubeᵀᴹ pointed out in a comment, LIMIT in combination with OFFSET can also be used. For a trivial case with only one partition, it is likely the most efficient solution:

SELECT t1.id, t1.val 
FROM t t1
LIMIT 1000000000000 OFFSET 2
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.