SQL sort order

Status
Not open for further replies.

pattinso

Member
Messages
48
Reaction score
2
Points
8
I've tried various options to retrieve a list of records sorted ascending with the NULL records at the end but to no avail. Is there a way to do this in MySQL on X10?
 

fifthape

New Member
Messages
14
Reaction score
0
Points
1
Try this.

SELECT record_column FROM table_name ORDER BY CASE WHEN record_column is null THEN 1 ELSE 0 END, record_column ASC
 
Last edited:

pattinso

Member
Messages
48
Reaction score
2
Points
8
Try this.

SELECT record_column FROM table_name ORDER BY CASE WHEN record_column is null THEN 1 ELSE 0 END, record_column ASC

Nope. Tried:

ORDER BY CASE WHEN dcc is null THEN 1 ELSE 0 END,dcc ASC,namefirst

and the order is as if I requested
ORDER BY CASE WHEN dcc,namefirst
Nulls are still at the top

dcc is a varchar(4) field
 

pattinso

Member
Messages
48
Reaction score
2
Points
8
Got it. Empty is not the same as NULL. Just had to change [dcc is null to [dcc = '']. Works now.
 

fifthape

New Member
Messages
14
Reaction score
0
Points
1
Good to hear! I was kinda scratching my head because I tested the command I posted on a table in my phpAdmin and it worked for me. :D
 
Status
Not open for further replies.
Top