Comments - ORDER BY

6 years, 2 months ago Tadas Balaišis

Be aware with null values, they always come first. If you want "nulls last" order, you have to use additional pseudo-column, like this:

order by if(col is \N,1,0),col

 
2 months, 2 weeks ago Ingo Tomahogh-Willms

At least in MariaDB 10.5.8, NULL is ordered as lowest value.

Therefore,

ORDER BY -updated_at

and

ORDER BY updated_at DESC

are not the same if the updated_at (datetime) column contains some NULL values: The first one will sort NULLs first, the second one sorts NULL values last, while both sort actual datetimes in descending order.

 
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.