Oracle ORDER BY Clause πΆΒΆ
Prerequisites: SELECT Statement
Mentor's Note: Data in a table is like a pile of laundry.
ORDER BYis the process of folding it and putting it into neat drawers. Without this clause, Oracle does not guarantee any specific order! π‘
π The Scenario: The Leaderboard πΒΆ
You are managing a sports academy.
- Goal: You want to see the top scorers first.
- Action: You sort the list by score in Descending order.
π» 1. Basic SyntaxΒΆ
Example: Sort by Salary (High to Low)ΒΆ
ποΈ Architect's Note: Nulls & Performance π‘οΈΒΆ
- NULLS FIRST/LAST: In Oracle, NULLs are treated as the "Largest" values. By default, they appear at the bottom in ASC order. You can change this!
- Expensive Sorts: Sorting is one of the most resource-intensive operations in Oracle. It uses the
TEMPtablespace. Avoid sorting millions of rows if you only need the Top 10!