Returning full duplicate rows using Laravel’s query builder

I am looking to return the full information on duplicate records from my table.

I am currently using the following:

DB::table($entity['table'])
                ->select('*')
                ->groupBy($entity['columns'])
                ->havingRaw('COUNT(*) > 1')
                ->get();

Which is great, it returns the duplicate records, however, this only returns one of the records I need to return all the duplicates so that I can greet the user with a choice on which one to delete or keep.

How can I modify the above query to accomplish that?


Source: laravel

Leave a Reply