table: companies
ID | companyName
................................
1 | company1
2 | company2
3 | company3
4 | company4
table:invoice
ID | companyID
................................
1 | 1
2 | 1
3 | 3
4 | 2
table: invoiceinput
ID | invoiceID | inputTotal
................................
1 | 1 | 100
2 | 1 | 200
3 | 1 | 123
4 | 3 | 211
the field total is
to describe: I have base of companies in table "companies", invoices (in table "invoice") note that several invoices can be applied to one company, and content of invoice (in invoiceinput table). several invoiceinput item can be aplied to one invoice. there is foreign key on invoice.companyID to companies.ID, and on invoiceinput.invoiceID to invoice.ID.
so I want result like this:
companyName | sum of totals
...............................................
company1 | 423
company2 | 0
company3 | 0
company4 | 211
So sum of totals column should contain data that is sum of all totals that are in all invoices which is made for a certain company.
I hope I described it well.