Reputation: 351
How can I find duplicate values in database with Laravel. I want the results like this:
name_data - amount
(Column name along with amount of duplicate data)
I used this code but it didn't work:
$duplicates = DB::table('jadwals')
->select('nama_peserta', (DB::raw('COUNT(nama_peserta)')))
->groupBy('nama_peserta')
->having(DB::raw('COUNT(nama_peserta) > 1'))
->get();
Please help me, thank you!
Upvotes: 0
Views: 2061
Reputation: 13394
You have a syntax error with having DB::raw()
,
try:
->having(DB::raw('COUNT(nama_peserta)'), '>', 1)
or
->havingRaw('COUNT(nama_peserta) > 1')
Upvotes: 2