Hello guys, today I had a problem with sorting MySQL. the problem is I want to sort by one column but some of the rows are empty. so I go through the internet and found a solution.
Using the IS (NOT) NULL operator. (Works for all data types.) In this trick, we can rely on the fact that
IS NULL
returns a 1 for all NULL expressions and a 0 otherwise. To make NULLs appear last while sorting in ascending order, we can use the following query:learnsql.comSELECT * FROM paintings ORDER BY year IS NULL, year;
Image by fullvector on Freepik