问题描述:

I'm doing a query to get all the purchases from the db. For example

orders = PurchaseOrders.all

I in the same query, how can I select only the first hundred orders(1-100) or just the next 100(101-200) etc..?

Thank you

网友答案:

You can use limit and offset:

PurchaseOrders.limit(200).offset(100)

which meant start from 200 and take 100 records. More info here. Or with take:

PurchaseOrders.offset(100).take(400)

take 400 records starting from 100.

网友答案:

For the first 100 records;

orders = PurchaseOrders.first(100)

and last 100 records;

orders = PurchaseOrders.last(100)

or by IDs,

orders = PurchaseOrders.find([100, 201])
相关阅读:
Top