In MySQL
NULL
values are considered lower than any non-NULL value, therefore, NULL
values appear first when the order is ASC
(ascending), and ordered last when the order is DESC
(descending)Sort In Ascending Order With NULLs Last
Using The Minus Operator:
In MySQL
NULL
values are considered lower in order than any non-NULL value, except if a -
(minus) character is added before the column name while sorting.Query:
SELECT * FROM user ORDER BY -date_login DESC
While this may work well for numbers and dates, it may not be the best solution to sort fields with alpha or alphanumeric values, for those you may want to try the other methods discussed in this article.
Không có nhận xét nào:
Đăng nhận xét