Sam.tuver
Sam.tuver

Reputation: 709

Get From specific ID to Last

I am learning mysql and having a small issue .

I am trying to get data from one specific ID in my table to the last element.

This is what i'm currently using :

$b = TableClass::orderBy('created_at', 'desc')->take(100)->get()->reverse();

This basically takes the last element and 100 rows before it and then put them in order.

if last_id 515 and required_id = 419

What is the best query to get all rows from 419 to 515 in order.

Eloquent is preferred but i can also use Direct queries.

Upvotes: 0

Views: 65

Answers (1)

Prix
Prix

Reputation: 19528

According to their guide, this is what you want:

From 419 to last:

$b = TableClass::orderBy('id','asc')->where('id', '>=', 419)->get();

Which in query is similar to:

SELECT * FROM your_table WHERE id >= 419 ORDER BY id

Upvotes: 1

Related Questions