Worked Examples · Example 9.10
Q.Select details of all the employees in descending order of their salaries.
Uttar Pradesh UpmspTextbookSubjective· 2mImportance★★★★★
20% · 19/95 Questions
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 →ORDER BY Salary DESC sorts descending (highest first). Run against the chapter's own EMPLOYEE table (Table 9.8), it lists all 10 employees from Kritika (60000) down to Aaliya (10000).
The query
SELECT *
FROM EMPLOYEE
ORDER BY Salary DESC;
ORDER BY without DESC sorts ascending by default (as in the previous Example 9.9); adding the DESC keyword reverses it, so the employee with the highest salary appears first.
Sorting Table 9.8 by Salary, descending
| Salary | EmpNo | Ename |
|---|---|---|
| 60000 | 102 | Kritika |
| 50000 | 110 | Tanya |
| 48000 | 106 | Sanya |
| 45000 | 103 | Shabbir |
| 42000 | 109 | Daribha |
| 34000 | 105 | Joseph |
| 29000 | 108 | Nachaobi |
| 19000 | 104 | Gurpreet |
| 15000 | 107 | Vergese |
| 10000 | 101 | Aaliya |
Output:
mysql> SELECT * FROM EMPLOYEE
-> ORDER BY Salary DESC;
+-------+----------+--------+-------+--------+
| EmpNo | Ename | Salary | Bonus | DeptId |
+-------+----------+--------+-------+--------+
| 102 | Kritika | 60000 | 123 | D01 |
| 110 | Tanya | 50000 | 467 | D05 |
| 106 | Sanya | 48000 | 695 | D02 |
| 103 | Shabbir | 45000 | 566 | D01 |
| 109 | Daribha | 42000 | NULL | D04 |
| 105 | Joseph | 34000 | 875 | D03 | …
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.