MYSQL order by - NULL values impacting my results

Jwrbloom

A table of about 200 rows, 15 of which will have a numeric value rankClass (1-15). The rest will have NULL values.

ORDER BY rankClass,nameLast

It posts the rows with NULL values first, and when I add DESC, of course, it lists it set rows first, but 15-1. I'd like it to list those with values first, 1-15, then the rest by nameLast.

I've tried coalesce, but it goes 1,10,11,12,13,14,15,2,3,4,5,6,7,8,9.

How would I get the results I'm looking for?

Thank you.

Mureinik

You could explicitly check for nulls in the rankClass, and order by an expression that moves them to the end:

SELECT   *
FROM     mytable
ORDER BY rankClass IS NULL, -- false comes before true
         rankClass

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

JSON in MySQL, returning null results

Mysql select order results by parameter

How do I get rid of null values in my SQL results in java?

MySQL null values in Golang

fixing my table using MySQL with null values

Return query results with union all in same order as the values in my `IN(…)` statement

Order MySql results by DateTime value

MYSQL is not null, not skipping results that are null

Order by NULL values with mysql

Is it safe to rely on the order of null values in an order by?

Sort results by number of NOT NULL values

Order results of a query by values

How do I order mysql query results by values from a joined table's rows (not columns)?

Couchbase order by retuning null results

When i send my form, my checkboxes values results always NULL

Adding values to MySQL results array

Results not showing in MySQL with NULL values

SQL - Insert NULL entry with Union then order by results

Mysql Query not returning my results

How to return NULL values in MySQL query if no results in LEFT JOIN and WHERE clause are found

Concatenate results with some null values

SQLite: Order by number of NULL values

"Order by" results of "Group By" in MySQL

Mysql order by field with given values which has NULL in between

MySQL group by null and not null values

mysql INSERT INTO results in NULL values

Mysql select ignores null values on return results

MYSQL Search results not showing In Order of Results By Their Name

How do you order the results of mySQL group_concat() when all the values come from one column?