Suppose I have three tables company, event, offer having 1-N-N relation.
I want trying to return all sum of the offers that a company has.
Eg Company A has 3 events and this 3 events have 1, 2,4 offers respectively.
So it is aggregated to 7 for company A.
This is what I have tried and It works fine, just that the company with 0 offers is not returned
SELECT company.name,company.sector,count(*) as offers
FROM event
RIGHT JOIN company ON event.company_id = company.id
RIGHT JOIN offer ON event.id = offer.event_id
GROUP BY company.id
LIMIT ${limit} OFFSET ${offset};
--------+--------------+----------------+
| name | sector | offer |
+--------+--------------+----------------+
| A | AA | 7 |
| B | BB | 3 |
| C | CC | 1 |
+--------+--------------+----------------+
D DD 0
Sample Output shown above, where data inside the box is the current output and including the data outside the box as well is the expected output