Outer Join on all columns if possible, or a subset of columns if not possible, and sum
You will need three left joins. Semipseudo code as stuck in trafic
Select sum(coalesce(l1,l2,l3 quantity)
From t1
Left Join t2 as l1 on a,b,c
Left join t2 as l2 on a,b and l1 is null
Left join t2 as l3 on a and l1 is null and l2 is null