Differences

This shows you the differences between two versions of the page.

oracle-to-mysql:null_order_by [April 06, 2013 2:05 pm]
sqlines
oracle-to-mysql:null_order_by [April 06, 2013 2:28 pm] (current)
sqlines
Line 50: Line 50:
| France | | France |
| Singapore | | Singapore |
 +
 +If ORDER BY contains multiple columns, you can specify NULLS FIRST or NULLS LAST for each column:
 +
 +**Oracle**:
 +
 +<code sql>
 +  SELECT name, value
 +  FROM
 +    (SELECT 'Singapore' AS name, 1 AS value FROM dual UNION ALL
 +     SELECT NULL, 2  FROM dual UNION ALL
 +     SELECT 'France', 3  FROM dual UNION ALL
 +     SELECT 'France', NULL FROM dual) t
 +  ORDER BY name NULLS FIRST, value DESC NULLS LAST;
 +</code>
 +
 +Result:
 +
 +| **name** | **value** |
 +| NULL | 2 |
 +| France | 3 |
 +| France | NULL |
 +| Singapore | 1 |
   
In MySQL, NULL values always go first in ascending order: In MySQL, NULL values always go first in ascending order: