Mostafa Talebi
Mostafa Talebi

Reputation: 9183

How to select a range of rows but offset it from a specific id

If I want to select , let's say, 5 records, I do this:

SELECT * FROM mytable LIMIT 5

If I want to add an offset, I do this:

SELECT * FROM mytable OFFSET 5 LIMIT 5;

But what should I do if I want to offset from a specific id? Something like this:

SELECT * FROM mytable OFFSET FROM id = 30 IMIT 5

Upvotes: 0

Views: 150

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269873

Using limit without an order by is to be discouraged. Let me assume this is what you want:

select *
from mytable
where id >= 30
order by id
limit 5;

Upvotes: 1

Related Questions