I have two tables - Boxes and Items:
Boxes
Id|Name
1|Box1
2|Box2
3|Box3
Items
Id|Size|Box
1|2 |1
2|3 |1
3|2 |2
4|5 |2
I need to get all items from Boxes joined with MAX(Size) from Items. If there is no corresponding Size from Items, Size should be 0.
The results should be like this:
Result
Id|Name|Size
1|Box1|3
2|Box2|5
3|Box3|0
From what I've read there are numerous ways, like subqueries or using GROUP BY (which, apparently, isn't allowed in MSSQL). What is the most efficient method which can work across any (or at least) most RDBMS?