Usage of order

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.