You want to sort Nulls and Blanks last and read all the solutions that use either the Coalesce or If functions in column order.
My problems are not for me, because the column that I am sorting is dynamically set by the PHP script that creates the query, and some of my columns are in two tables in my join.
$sortcol="boat";
$sql= "SELECT fleet,b.boat as boat,owner FROM boats as b
LEFT JOIN owners as o ON b.boat=o.boat
ORDER BY $sortcol";
This works fine, I can change the $ sortcol variable, and my output pin works fine except for the zeros and spaces at the top.
Based on other posts, I tried this
$sortcol="boat";
$sql= "SELECT fleet,b.boat as boat,owner FROM boats as b
LEFT JOIN owners as o ON b.boat=o.boat
ORDER BY IF($sortcol is NULL,1,0), $sortcol";
. "- ORDER BY ". , b.boat , , , .
, , orderby, .
.