lundi 29 juillet 2019

Having issues with groupBy with a join

I am doing these query to get all records with specific gender from different tables:

$q = DB::table('bondings')
            ->join('businesses', 'bondings.business_id', '=', 'businesses.id')
            ->select('bondings.*', 'businesses.solicitante_sexo')
            ->whereIn('businesses.solicitante_sexo', ['Masculino','Femenino','Otro'])
            ->groupBy('bondings.business_id');

The query works with out the groupBy, but give all records repeting business_id, and i need to goup them so i will have only one record by business_id

I am getting this error from laravel 5.7:

SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'ovimipymes.bondings.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (SQL: select `bondings`.*, `businesses`.`solicitante_sexo` from `bondings` inner join `businesses` on `bondings`.`business_id` = `businesses`.`id` where `businesses`.`solicitante_sexo` in (Masculino, Femenino, Otro) group by `bondings`.`business_id`)



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/314PJ9H
via IFTTT

Aucun commentaire:

Enregistrer un commentaire