Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jerauf's avatar

Delete all but the first 50 rows in a query

I want to keep only the first 50 rows that are returned by a query. I tried using skip(50) but that didn't work.

Any ideas?

0 likes
2 replies
jlrdw's avatar

A derived column, then greater than 50.

jerauf's avatar

Sorry, I don't know what that means. And a google search didn't bring up anything useful. Only about calculated fields.

I've got a table with 100 rows. I want to keep the first 50 and delete the rest with one query. Here's what I have:

    ActivityLog::orderBy('updated_at', 'desc')
		->skip(50)
		->delete();

But it deleted everything in the table.

Please or to participate in this conversation.