Sam.tuver
Sam.tuver

Reputation: 709

Mysql / Eloquent - return every 3 rows

I have this query :

$b = Class::orderBy('created_at', 'desc')->take(50)->get();

This gets me the last 50 elements in my table . However i only want every 3 rows e.g : valu1 , value3 , value5 , value6

Is there a way to process that directly in the sql query without additional code ?

Thanks

Thanks

Upvotes: 1

Views: 560

Answers (1)

Odin Thunder
Odin Thunder

Reputation: 3547

If you use Laravel of latest versions:

$b = Class::orderBy('created_at', 'desc')->nth(3)->get();

More about nth()

Upvotes: 1

Related Questions