Mysql Order NULL value

Source: https://www.designcise.com/web/tutorial/how-to-order-null-values-first-or-last-in-mysql

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:

Cold Turkey Blocker

 https://superuser.com/questions/1366153/how-to-get-rid-of-cold-turkey-website-blocker-get-around-the-block Very old question, but still wan...