I have this code to find duplicates, but i compare All columns in same row, also it returns only one row

$groupBy = explode(',',$request['fields']);
   $duplicates = DB::table($module)
    ->havingRaw('COUNT(*) > 1')

What I need is to find the duplicates with (OR) not (And) I want to find if there's a duplicate in Name or in Phone.

I also wanted to return All of the founded recorded to determine which one should I delete.

closed as off-topic by fmsthird, Priyank, Aasim Goriya, Amit Bera May 16 at 10:03

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced OR seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – fmsthird, Priyank, Aasim Goriya, Amit Bera
If this question can be reworded to fit the rules in the help center, please edit the question.


Try this code,

$duplicates = DB::table($module)
      ->select('Name','Phone', DB::raw('COUNT(*) as count')
      ->groupBy('Name', 'Phone')
      ->having('count', '>', 1)

Not the answer you're looking for? Browse other questions tagged or ask your own question.