Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Xanger's avatar

ByGroup is not working

Hi, I would need to select a single data, when there are more elements with "id_gioco" equal

eg:

{
id: 3703,
id_gioco: 203,
id_console: 4,
data: "2017-06-01",
immagine: "upload/cover/cover__1ccd8871012ec80fac18fdce9acd85c7.jpg",
appid: "",
distribuito: 30,
giochi: [
{
id: 203,
nome: "Tekken 7 Fated Retribution",
developer: "56",
publisher: "30",
copertina: "853874411.jpeg",
attivo: 1,
ultima_mod: "1464610402",
id_trailer: "",
slug: "tekken-7-fated-retribution"
}
]
},
{
id: 3704,
id_gioco: 203,
id_console: 5,
data: "2017-06-01",
immagine: "upload/cover/cover__d13dcebb782f2167fd717ff7c9dcae4c.jpg",
appid: "389730",
distribuito: 30,
giochi: [
{
id: 203,
nome: "Tekken 7 Fated Retribution",
developer: "56",
publisher: "30",
copertina: "853874411.jpeg",
attivo: 1,
ultima_mod: "1464610402",
id_trailer: "",
slug: "tekken-7-fated-retribution"
}
]
},

Here is a screenshot to see the json better

As you can see, both elements have id_gioco: 203 in common.

This is my code:

            $giochi = InfoGiochi::with('Giochi')
                ->whereMonth('data', '=', date('m'))
                ->whereYear('data', date('Y'))
            ->get();

I try with:

->groupBy('id_gioco')

But laravel gives me the error:

SQLSTATE[42000]: Syntax error or access violation: 1055 'beta.info_giochi.id' isn't in GROUP BY (SQL: select * from info_giochi where month(data) = 06 and year(data) = 2017 group by id_gioco)

0 likes
1 reply

Please or to participate in this conversation.