> With Multiple Columns:
SELECT name, dept, commission
FROM employees
ORDER BY dept ASC, commission DESC NULLS LAST;
• Within each department → commission highest first → NULLs at the very end!
> Quick Summary:
• ORDER BY = sorts results - always the last clause in the query
• Can sort by column name, alias, or position number
• Column alias CAN be used in ORDER BY - it runs after SELECT
• ASC = low to high (default - no need to write it)
• DESC = high to low - must write explicitly
• Each column in multi-sort can have its own ASC or DESC direction
• Dates sorted chronologically - DESC gives most recent first
• ASC → NULLs at bottom by default
• DESC → NULLs at top by default
• NULLS FIRST → forces NULLs to top regardless of sort direction
• NULLS LAST → forces NULLs to bottom regardless of sort direction
#OracleSQL#ORDERBY#ASC#DESC#NullsFirst#NullsLast#LearnSQL#SQLBeginners#Day15#100DaysOfCode#TechTwitter
Same for #Comparator:
* to compare objects by an attribute, use `Comparator.comparing`
* to sort by several attributes, chain comparators with `thenComparing`
* reverse with `reversed`
* use `nullsFirst` or `nullsLast` to handle `null`
More: dev.java/learn/writing-and-c…