Answer the question
In order to leave comments, you need to log in
How to come up with an auto-cleanup table?
Guys, I have a table with fields
id
name
vid
comm
created_at
updated_at
Answer the question
In order to leave comments, you need to log in
After reading the docs ... As a result, the ideal option for the Laravel framework without a bicycle will fail:
$count = DB::table('tbl_name')->where('vid', '=', $vid)->count();
DB::table('tbl_name')->where('vid', '=', $vid)
->orderBy('created_at', 'asc')
->skip(500)->take($count-500)
->delete();
There are many solutions, here is one of them as an example:
1) Using count and group by we get the list vid - quantity, where the number is more than 500
2) Iterate through the vid array, execute a delete query with a limit, and sort by date.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question