I have a table with People '
Columns
And the table with Notes ':
Columns
I want to select the number of notes for all authors from the people table, their name and age, but I want to group it by PERSON identifier, not by name. There are many situations where people have the same name, but the identifier is obviously always different.
EXAMPLE (input)
PEOPLE:
ββββββ¦ββββββββ¦ββββββ
β ID β NAME β AGE β
β βββββ¬ββββββββ¬ββββββ£
β 1 β John β 12 β
β 2 β Annie β 29 β
β 3 β John β 44 β
ββββββ©ββββββββ©ββββββ
NOTES:
ββββββ¦ββββββββ¦ββββββββββββ
β ID β TEXT β FK_AUTHOR β
β βββββ¬ββββββββ¬ββββββββββββ£
β 1 β 'aaa' β 1 β
β 2 β 'aaa' β 1 β
β 3 β 'aaa' β 2 β
β 4 β 'aaa' β 2 β
β 5 β 'aaa' β 3 β
ββββββ©ββββββββ©ββββββββββββ
Expected Result:
βββββββββ¦ββββββ¦βββββββββββββ
β NAME β AGE β TOTALCOUNT β
β ββββββββ¬ββββββ¬βββββββββββββ£
β John β 12 β 2 β
β Annie β 29 β 2 β
β John β 44 β 1 β
βββββββββ©ββββββ©βββββββββββββ
When I select data, I also need to group by name if I want to select this column, because if I do not want, I get an error.
source
share