I have a 3 table setup ( Branches, Product, and Waste ). The goal is to get a result including all enabled branches, with all enabled products and their waste for the entire week
Table: Branches
| id | Branch Name | Is Enabled |
|---|---|---|
| 1 | Big Branch | 1 |
| 2 | Medium Branch | 0 |
| 3 | Small Branch | 1 |
Table: Waste
| id | Branch ID | Product ID | week number | Mon | Tues | Wed | Thu | Fri | Sat | Sun |
|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 30 | 10 | 0 | 5 | 0 | 0 | 0 | 0 |
Table: Product
| id | Name | Is Enabled |
|---|---|---|
| 1 | Bread | 1 |
| 2 | Cream | 1 |
| 3 | Rice | 1 |
| 4 | Milk | 0 |
Ideal Result
| waste.id | branch id | branches.name | week number | product.id | product.name | Mon | Tues | Wed | Thu | Fri | Sat | Sun |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 1 | Big Branch | 30 | 1 | Bread | 10 | 0 | 5 | 0 | 0 | 0 | 0 |
| null | 1 | Big Branch | null | 2 | Cream | null | null | null | null | null | null | null |
| null | 1 | Big Branch | null | 3 | Rice | null | null | null | null | null | null | null |
| null | 3 | Small Branch | null | 1 | Bread | null | null | null | null | null | null | null |
| null | 3 | Small Branch | null | 2 | Cream | null | null | null | null | null | null | null |
| null | 3 | Small Branch | null | 3 | Rice | null | null | null | null | null | null | null |
SQL Query Attempt
SELECT waste.id, product.id, product.name, product.is_enabled waste.product_id, waste.id, week_number, waste.branch_id, branches.id, branches.branch_name, branches.is_enabled,
mon, tue, wed, thu, fri, sat, sun
FROM `product`
LEFT JOIN waste
ON product.id = waste.product_id
LEFT JOIN branches;
What kind of join should be used to achieve this result?