Estoy realizando la siguiente consulta sobre mi gestor de base de datos. la cual funciona perfectamente mostrando la info esperada:
select
ca.id,
a.name,
a.description,
t.name as type_activity,
c.name as category,
uca.created_at
from activities as a
join category_activities as ca on a.id = ca.activity_id
join user_category_activity as uca on uca.category_activity_id = ca.id
join type_activity as t on a.type_activity_id = t.id
join categories as c on c.id = ca.category_id
where uca.state_id = 2 and uca.user_id = 3 and c.id = 65
group by id
order by uca.created_at
Pero al pasar la consulta a laravel, de la siguiente manera:
$activities = DB::table('activities as a')
->join('category_activities as ca','a.id','=','ca.activity_id')
->join('user_category_activity as uca','uca.category_activity_id','=','ca.id')
->join('type_activity as t', 'a.type_activity_id','=','t.id')
->join('categories as c','c.id','=','ca.category_id')
->select('ca.id',
'a.name',
'a.description',
't.name as type_activity',
'c.name as category',
'uca.created_at')
->where('uca.user_id', 3)
->where('c.id', 65)
->where('uca.state_id',2)
->groupBy('ca.id')
->orderBy('uca.created_at','DESC')
Me aparece un error "Syntax error or access violation: 1055 'ennlacebox.ca.id' isn't in GROUP B", el cual deja de aparecer en cuanto añado todos los campos en el group by, así:
->groupBy('a.id','ca.id','a.name','a.description','t.name','c.name','uca.created_at')
Pero en ese momento el GroupBy deja de ser inservible pues necesito que la información se me agrupe por el campo 'ca.id'
ayuda por favor, gracias