This is the kicker
->where('parent_id', $this->brandId)
This might shed some light
https://chartio.com/learn/databases/how-to-find-duplicate-values-in-a-sql-table/
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a table of Shops and there is some duplicates records and i need to get them out but with some conditions :
OR
i have used this solution but it only get 1 record and i want to get all duplicate records and also group them.
Shop::where(function ($query) {
$query->whereIn('id', function ( $query ) {
$query->select('id')
->from('brands')
->where('parent_id', $this->brandId)
->groupBy(['name', 'adress'])
->havingRaw('count(*) > 1');
})
->orWhereIn('id', function ( $query ) {
$query->select('id')
->from('brands')
->where('parent_id', $this->brandId)
->groupBy(['type', 'status'])
->havingRaw('count(*) > 1 ');
});
})
->get();
Please or to participate in this conversation.