How i can group my records?

I have this records:

I need to group this records by class_id, so i will be one array with two positions.

I try:

const quizAbertos = await Database

   .select('*')

   .from('student_quiz_historics')

   .where('student_id', idEstudante)

   .where('execution_back_status', 'Enviado Perguntas')

   .groupBy('class_id')

But i’m getting:

select “student_quiz_historics”.* from “student_quiz_historics” where “student_id” = $1 and “execution_back_status” = $2 group by “student_quiz_historics”.“class_id” - column “student_quiz_historics.id” must appear in the GROUP BY clause or be used in an aggregate function

What database are you using?

Hey @veronesecoms! :wave:

This is a common SQL issue, I let you read this post for more information.

I’m using postgres
I’m still trying to do this :confused:

Basically what this error is saying that it doesn’t know what to do with ID, since it’s unique and can’t “count” or “group” IDs together anyhow.
What you might want to look into is array_agg or don’t select ID at all. Depends on your application logic