MySQL field sorting
In an SQL statement, if the field you want to sort is empty, how do you handle it if you want to put it in the back?
------Solution--------------------
If the field you want to sort is empty, the default is to put the empty row in front. Add a desc keyword can be in reverse order, that is, empty in the last side
------Solution--------------------
Suggest you post:
Create TABLE .....
Insert into Table ....
and expected results.
------Solution--------------------
ORDER by IsNull (' fields to sort by value ')
You can put the empty line in the back, you mean it?
------Solution--------------------
(... WHERE field name is not NULL GROUP by field name)
UNION (...) WHERE field name is NULL)
......
------Solution--------------------
... order by sort field = ' or sort field ID null, sort field
------Solution--------------------
Why the word blank Ah, build the table should try to be non-empty.
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