LMSouq
database Open

MySQL Orderby a number, Nulls last

JO
JonB
1 month ago
3 views
Problem Description
Currently, I am doing a very basic OrderBy in my statement. SELECT * FROM tablename WHERE visible=1 ORDER BY position ASC, id DESC The problem with this is that NULL entries for 'position' are treated as 0. Therefore, all entries with position as NULL appear before those with 1,2,3,4. For example, NULL, NULL, NULL, 1, 2, 3, 4 Is there a way to achieve the following ordering? 1, 2, 3, 4, NULL, NULL, NULL.

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base