When ordering by order in MySQL, the data exists null to do

Source: Internet
Author: User
Tags null null

Order by sorting is the most commonly used feature, but sorting can sometimes encounter null NULL in the case of data, so the sorting will be messy, here in MySQL as an example, to record the problems I encountered and solve ideas.

Problem:

Page to implement table row mouse Drag sort, I used angularjs integrated with a TABLEDND open source plug-in, can be implemented, and then add a sort field IndexID in the database table, but the original large amount of data is not sorted, so the field is null.

When the order is done, the null data will be in the front row.

Write a test sheet to simulate the following effects:

Workaround:

  • Best practices: Use a small trick in MySQL, precede the field with a minus sign, minus sign, ASC to DESC, DESC to ASC

  • Regenerate a column, such as Agenull, with the IS null operator, change the row of the null value to 1, the non-null value of the row to 0, sort the field first, and then sort the age

  • Evaluate the age column directly using the IsNull function, as is the case with the first method

Methods also try databases such as SQL Server and Oracle

When ordering by order in MySQL, the data exists null to do

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.