Order Two Columns Independently
A medium-tier problem at 61% community acceptance, tagged with Database. Reported in interviews at Booking.com and 0 others.
You're staring at a SQL problem on Booking.com's assessment that asks you to order two columns independently. This one trips up candidates who assume a single ORDER BY clause will do the job. The trick isn't about sorting complexity, it's about understanding that SQL's standard ordering applies a single sort order across the entire result set. You need to rethink the structure. If you blank on the pattern during the live OA, StealthCoder reads the problem and surfaces a working solution in seconds, invisible to the proctor.
Companies that ask "Order Two Columns Independently"
Order Two Columns Independently is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop.
Get StealthCoderThe core problem: candidates try to ORDER BY column1, column2 and expect column1 sorted ascending while column2 sorts independently. That's not how SQL works. The real solution involves window functions or subqueries that apply ranking or row numbering separately to each column, then reconstruct the output. Common pitfall is writing a query that technically runs but returns wrong results because you're sorting the entire dataset once, not each column independently. You need ROW_NUMBER() OVER (ORDER BY col1) and ROW_NUMBER() OVER (ORDER BY col2) on the same table, then join or reconstruct. This isn't an obvious path if you haven't seen the pattern. StealthCoder is your hedge when the obvious SELECT...ORDER BY fails in the live environment.
Pattern tags
You know the problem.
Make sure you actually pass it.
Order Two Columns Independently recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Order Two Columns Independently interview FAQ
Is this problem actually a common ask at Booking.com?+
Yes. It's on their assessment list and acceptance is solid at just over 60%, meaning it's moderately difficult but solvable with the right approach. Booking deals with heavy database queries, so SQL window function literacy matters for their team.
What's the trick I'm missing if my ORDER BY doesn't work?+
You're sorting the result set as a whole. To order two columns independently, use window functions (ROW_NUMBER() OVER) with separate ORDER BY clauses per column, not a global ORDER BY. Then reconstruct the output by joining on the row numbers.
Do I need to know window functions to solve this?+
Yes. ROW_NUMBER() OVER (ORDER BY...) is the standard approach. If you're weak on window functions, this problem is a good reason to brush up before the OA.
Will this problem show up in other assessments I take?+
It's reported from Booking.com specifically. Other companies may ask similar independent-ordering logic, but this exact problem is Booking-specific in the data.
How much time should I spend on this if I get stuck?+
If standard ORDER BY isn't giving you the right output within 5-10 minutes, pivot to window functions. The acceptance rate suggests it's solvable once you know the pattern, so don't spin wheels on syntax.
Want the actual problem statement? View "Order Two Columns Independently" on LeetCode →