-1

I have a simple table with null values across the

row(counter, null 3456,10,null,45,null).

I am trying to make the data look like

(counter, 3456,10,45,null,null,null).

So far I have tried

SELECT * 
FROM alpha2
ORDER BY IS NULL( Value1, Value2,Value3,Value4,Value5,Value6);
  • Value is the column name

I have also tried

SELECT * FROM alpha2 ORDER BY -rank DESC;


Counter Value1 Value2 Value3 Value4 Value5 Value6 <- columns
Count1  3456   10     45      null  null  null .   <-rows
S. Caruso
  • 31
  • 1
  • 7

1 Answers1

1

On MS-SQL Server, the ORDER BY ... ASC clause will always place NULL values first. On MS-SQL Server, the ORDER BY ... DESC clause will always place NULL values last.

On Oracle, the ORDER BY ... ASC clause will always place NULL values last. On Oracle, the ORDER BY ... DESC clause will always place NULL values first.

The SQL standard does not explicitly define a default sort order for Nulls. Instead, on conforming systems, Nulls can be sorted before or after all data values by using the NULLS FIRST or NULLS LAST clauses of the ORDER BY list, respectively. This is the case for Oracle RDBMS. MS-SQL Server does not implement this functionality.

Sample code for sorting nulls in MySQL: Here, Data is assumed as Column and Table as Table:

    select Data
    from Table
    order by case when Data is null then 1 else 0 end, Data
Gulshan Yadav
  • 424
  • 5
  • 13