The SQL standard does not define the order of rows when NULL values are present in the column on which the result is sorted. To control if NULL values should be sorted before or after non-NULL values, NULLS FIRST/LAST can be added to an ORDER BY clause

SELECT *
FROM person
ORDER BY middle_name NULLS LAST

If this feature is not present a workaround is to order by an expression:

SELECT *
FROM person
ORDER BY CASE 
           WHEN middle_name IS NLL THEN 'ZZZZZZZZZZZZZZZZ'
           ELSE middle_name
         END;

This workaround requires that the "magic value" never occurs in the real data.

Back to the SQL Feature Comparison