I'm new to Postgres -- and it's been years since I've done anything SQL related so I'm perhaps over-thinking this -- but...
I have a subquery which selects a bunch of IDs (cs_seed) to perform another query on.
What I'd like to be able to do is to maintain the order from the subquery. I've searched for hours and discovered the row_number() feature which seems promising, but I obviously can't use this in a WHERE IN query as it's returning multiple columns.
SELECT ca_seed, ca_biome, ca_percent
FROM colours_area
WHERE ca_seed IN (SELECT cs_seed, row_number() OVER (ORDER BY cs_percent DESC) AS rn
FROM colours_spawn
WHERE cs_biome = 140
ORDER BY cs_percent DESC LIMIT 10)
ORDER BY rn DESC;
Is there any way I can do this? Or is my approach wrong?