We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- SQL
- Basic Join
- Ollivander's Inventory
- Discussions
Ollivander's Inventory
Ollivander's Inventory
Sort by
recency
|
2092 Discussions
|
Please Login in order to post a comment
SELECT w.id, wp.age, w.coins_needed, w.power FROM Wands w JOIN Wands_Property wp ON w.code = wp.code WHERE wp.is_evil = 0 AND w.coins_needed = ( SELECT MIN(w2.coins_needed) FROM Wands w2 JOIN Wands_Property wp2 ON w2.code = wp2.code WHERE wp2.is_evil = 0 AND w2.power = w.power AND wp2.age = wp.age ) ORDER BY w.power DESC, wp.age DESC;
SQL SERVER
) ORDER BY wands.power DESC, wands_property.age DESC;
Holy subquery
SELECT id, age, coins_needed, power FROM Wands JOIN Wands_Property ON Wands.code = Wands_Property.code WHERE is_evil = 0 AND coins_needed = ( SELECT MIN(Wands2.coins_needed) FROM Wands Wands2 JOIN Wands_Property = Wands_Property2 ON Wands2.code = Wands_Property2.code WHERE Wands_Property2.is_evil = 0 AND Wands2.power = Wands.power AND Wands_Property2.age = Wands_Property.age) ORDER BY power DESC, age DESC;