I am getting this error PG::GroupingError when I try to run this query
Interaction.
order('interactions.created_at DESC').
joins({candidate: [:job,{application: :user}]}).
group('interactions.candidate_id')
What I'm trying to do is to group records using the candidate_id field, then for each group select the last(or first if there is just one record in the group). Executing the query above throws this error
PG::GroupingError: ERROR: column "interactions.id" must appear in the GROUP BY clause or be used in an aggregate function
I tried to resolve this by including the interactions.id in the group clause so I have the query below which kinda resolves the error but doesn't group the records
Interaction.
order('interactions.created_at DESC').
joins({candidate: [:job,{application: :user}]}).
group('interactions.candidate_id, interactions.id')
Any pointers on how to get this to work will be super helpful.
No responses yet.