LEFT JOIN on the Boxes table with the Chests table using the chest_id as the joining key.COALESCE function to substitute a 0 for any null values resulting from the LEFT JOIN (i.e., when a box does not contain a chest).Boxes table and the corresponding counts from the Chests table (if any) to get the total counts.erDiagram
Boxes ||--o{ Chests : contains
Boxes {
int box_id PK
int chest_id FK
int apple_count
int orange_count
}
Chests {
int chest_id PK
int apple_count
int orange_count
}