Usage of order
1. Processing of null in order
Default processing: Oracle considers null as the maximum value in order by, so if it is asc, it is placed at the end, and desc is placed at the top.
We can use nulls first or nulls last to control the null position.
Place null at the beginning: select * from student order by name asc nulls first
Put null at the end: select * from student order by name desc nulls last
2. Several sort statements:
Single Column ascending: select name from student order by name; (by default, even if asc is not written)
Single Column descending order: select name from student order by name desc;
Multi-column Ascending order: select id, name from student order by id, name;
Hybrid sorting of multiple columns: select id, name from student order by id desc, name asc; (sort by id first in descending order. If the IDs are the same, sort by name in ascending order)
3. force the first row of a column:
Select * from student order by decode (id, 3, 1, 2), id; // The value of id 3 is ranked first.