For my project I have a SQLite DB like the following:
https://sqliteonline.com/#fiddle-5aba37c986797mugjf9muddm
And I'm trying to obtain information about this with the query:
select
a.id_interno,
a.id_esterno,
count(b.id_ingrediente),
count(c.id_utente)
from
lista_spesa a
left join elemento_lista_spesa b on b.id_lista_spesa = a.id_interno
left join utente_lista_spesa c on c.id_lista_spesa = a.id_interno
group by
b.id_lista_spesa, c.id_lista_spesa;
But I obtain for the counts
ID_INTERNO|ID_ESTERNO|count(b.id_ingrediente)|count(c.id_utente)
1|-1|2|2
but I expect the following result:
ID_INTERNO|ID_ESTERNO|count(b.id_ingrediente)|count(c.id_utente)
1|-1|1|2
Why I have this wrong result? How can I fix?
Thanks!