How to use NULLS first

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ddddd
    New Member
    • Jun 2007
    • 4

    How to use NULLS first

    I have a table which has about 7 columns and the first row of all the collums is NULL.. when i do a select statement something like

    Select * from tablename order by col0 NULLS FIRST..

    It says the NULLS clause is not supported.

    If i use simply

    Select * from tablename order by col0 ..

    By default the Null row is displayed at the last but i created it in the first row..

    How to use the select statement such that i get the nulls values first as like i created..
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by ddddd
    I have a table which has about 7 columns and the first row of all the collums is NULL.. when i do a select statement something like

    Select * from tablename order by col0 NULLS FIRST..

    It says the NULLS clause is not supported.

    If i use simply

    Select * from tablename order by col0 ..

    By default the Null row is displayed at the last but i created it in the first row..

    How to use the select statement such that i get the nulls values first as like i created..
    you can have the nulls at the bottom if you do order by col0 desc but that would reverse the order of your col0 values as well.

    Comment

    • TertiaryKey
      New Member
      • May 2007
      • 5

      #3
      If you are happy to see a work column in the result table you can replace the null value with a literal for the purpose of ordering. e.g.:-

      Select coalesce(col0,' *NULL') as col0x, tablename.*
      from tablename order by col0x

      Comment

      • rickbray66
        New Member
        • Jun 2007
        • 7

        #4
        I have the same type of issue. I'm looking for a way to alter the behavior of NULLS last and have NULLS first across the board without having to modify a handfull of existing queries. Apparently, DB2 Express does not suppot the "NULL FIRST" condition of an ORDER BY clause. I'd prefer not to have to do that anyway, as I would prefer to keep my queries as database-independent as possible. Some DBMS will allow the NULL weight to be specified as a database or system parameter. I've yet to find a way to do this with DB2 Express. Anybody else have any suggestions?


        Rick

        Comment

        Working...