IMHO.... The better solution would be to discover how duplicate rows are being added and prevent it from happening.
Do you know how they get there? You could add database constraints to prevent it but I'm not sure how the application layer will respond. If you can find in the application where they get added you should be able to prevent it.
But to address your question directly.... you can get the count of rows, then delete them with a limit 1 less the count
$row_count = Article::where('url', '=', $url)->count()
DB:delete('delete from article where url = ? limit ?', array($url, ($row_count - 1)))
If you just need to clean up your records, you might consider just running a query directly... This looks like a really good way to do it, I believe I've tried it before:
ALTER IGNORE TABLE jobs ADD UNIQUE INDEX idx_name (site_id, title, company );
http://stackoverflow.com/questions/3311903/remove-duplicate-rows-in-mysql
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community