I'm looking for the most appropriate method to retrieve a list of duplicates in my database with laravel and eloquent.
Exemple of table records :
id : 1
artist_name : Jane Doe
track_name : The doe song
id : 2
artist_name : John Doe
track_name : A love song
id : 3
artist_name : Jane Doe
track_name : The doe song
id : 4
artist_name : John Doe
track_name : Happy
id : 5
artist_name : John Doe
track_name : Happy
Result expected (a list of all duplicates):
id : 1
artist_name : Jane Doe
track_name : The doe song
id : 3
artist_name : Jane Doe
track_name : The doe song
id : 4
artist_name : John Doe
track_name : Happy
id : 5
artist_name : John Doe
track_name : Happy
I tried the following piece of code but I'm getting an error :
$tracks = Track::whereIn('id', function ( $query ) {
$query->select('id')->from('tracks')->groupBy('track_name')->havingRaw('count(*) > 1');
})->paginate(20);
SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'table.tracks.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (SQL: select count() as aggregate from
trackswhereidin (selectidfromtracksgroup bytrack_namehaving count() > 1))
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2pr76Eg
via IFTTT
Aucun commentaire:
Enregistrer un commentaire