Q.Execute the following 2 queries and find out what will happen if we specify two columns in the ORDER BY clause:
SELECT * FROM EMPLOYEE ORDER BY Salary, Bonus;
SELECT * FROM EMPLOYEE ORDER BY Salary,Bonus DESC;
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →A second ORDER BY column is only a tie-breaker: it decides the order of rows that are equal on the first column. Table 9.8's Salary values are all distinct, so on the real data both queries return exactly the same row order — the difference between Bonus and Bonus DESC never actually shows up.
Why a second sort column matters — in general
ORDER BY sorts by its first column. If two rows tie on that column, their relative order would otherwise be undefined — a second column resolves that tie.
SELECT * FROM EMPLOYEE ORDER BY Salary, Bonus; -- Query 1
SELECT * FROM EMPLOYEE ORDER BY Salary, Bonus DESC; -- Query 2
Both sort primarily by Salary ascending. Query 1 breaks ties with Bonus ascending; Query 2 breaks ties with Bonus descending. DESC applies only to Bonus, not to Salary.
Running both queries on Table 9.8
| Salary | 10000 | 15000 | 19000 | 29000 | 34000 | 42000 | 45000 | 48000 | 50000 | 60000 |
|---|---|---|---|---|---|---|---|---|---|---|
| Ename | Aaliya | Vergese | Gurpreet | Nachaobi | Joseph | Daribha | Shabbir | Sanya | Tanya | Kritika |
Every salary in Table 9.8 is unique — there is no row with the same Salary as another. That means the tie-breaking rule (Bonus vs Bonus DESC) is never invoked on this data: with nothing to tie-break, the sort is decided entirely by Salary, and both queries return:
101 Aaliya 10000
107 Vergese 15000
104 Gurpreet 19000
108 Nachaobi 29000
105 Joseph 34000
109 Daribha 42000
103 Shabbir 45000
106 Sanya 48000
110 Tanya 50000
102 Kritika 60000
identically, for both queries. …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.