Ollivander's Inventory

  • + 0 comments

    MYSQL Solution: The concept is to create a Sub query to find the min of Coins_needed and Join all the tables together. SELECT id, age, Coins_needed, w1.power FROM Wands w1 JOIN Wands_property wp1 ON w1.code = wp1.code JOIN (SELECT w.code, power, min(w.coins_needed) AS Min_coins FROM Wands w JOIN Wands_property wp ON w.code = wp.code WHERE wp.is_evil = 0 GROUP BY w.code, w.power) AS CTE ON CTE.code = w1.code AND CTE.power = w1.power AND CTE.Min_coins = w1.Coins_needed ORDER BY w1.power DESC, age DESC