ON w.code = wp.code and -- Join on multiple properties. Start with the the codes. w.coins_needed = (select min(coins_needed) from Wands w1 join Wands_Property wp1 on ...