Loading ...
Sorry, an error occurred while loading the content.
 

RE: [SQLQueriesNoCode] Order if some order by fields are null

Expand Messages
  • Rob Richardson
    Thank you. That will help. RobR ... From: SQLQueriesNoCode@yahoogroups.com [mailto:SQLQueriesNoCode@yahoogroups.com] On Behalf Of Paul Livengood Sent:
    Message 1 of 8 , Jul 12, 2011
      Thank you. That will help.

      RobR

      -----Original Message-----
      From: SQLQueriesNoCode@yahoogroups.com
      [mailto:SQLQueriesNoCode@yahoogroups.com] On Behalf Of Paul Livengood
      Sent: Tuesday, July 12, 2011 11:30 AM
      To: SQLQueriesNoCode@yahoogroups.com
      Subject: Re: [SQLQueriesNoCode] Order if some order by fields are null

      i recommend using ISNULL and specifying a value for when bar.y is null.
      this helps you control the results.
    • Rob Richardson
      The ISNULL() function is not available in PostgreSQL. A quick Google search told me that ISNULL() is a Microsoft-specific addition to SQL Server. The
      Message 2 of 8 , Jul 12, 2011
        The ISNULL() function is not available in PostgreSQL. A quick Google
        search told me that ISNULL() is a Microsoft-specific addition to SQL
        Server. The standard function is COALESCE(). The basic idea is still
        good.

        Here's the link to the article I found telling me about this:
        http://stackoverflow.com/questions/2214525/what-is-the-postgresql-equiva
        lent-to-isnull

        RobR
      • Arnie Rowland
        NULL values will order before non-null values. You can use various methods to control ordering, such as ISNULL(). Regards, Arnie Rowland, MVP (SQL Server) You
        Message 3 of 8 , Jul 12, 2011
          NULL values will order before non-null values.
          You can use various methods to control ordering, such as ISNULL().


          Regards,

          Arnie Rowland, MVP (SQL Server)

          "You cannot do a kindness too soon because you never know how soon it
          will be too late."
          -Ralph Waldo Emerson




          -----Original Message-----
          From: SQLQueriesNoCode@yahoogroups.com
          [mailto:SQLQueriesNoCode@yahoogroups.com] On Behalf Of Rob Richardson
          Sent: Tuesday, July 12, 2011 8:27 AM
          To: SQLQueriesNoCode@yahoogroups.com
          Subject: [SQLQueriesNoCode] Order if some order by fields are null

          select foo.x, bar.y
          from foo left outer join bar on foo.a = bar.a order by y, x

          In some cases but not all, y will be null. Can I count on all records
          with non-null y values appearing before all records in which y is null?

          Thank you very much.

          RobR


          ------------------------------------

          Yahoo! Groups Links
        • Rob Richardson
          When I ran a query using the original form in PostgreSQL, the null values were sorted after the non-null values. I did not mention my platform because I
          Message 4 of 8 , Jul 12, 2011
            When I ran a query using the original form in PostgreSQL, the null
            values were sorted after the non-null values.

            I did not mention my platform because I thought this list was supposed
            to be platform-agnostic.

            RobR

            -----Original Message-----
            From: SQLQueriesNoCode@yahoogroups.com
            [mailto:SQLQueriesNoCode@yahoogroups.com] On Behalf Of Arnie Rowland
            Sent: Tuesday, July 12, 2011 11:43 AM
            To: SQLQueriesNoCode@yahoogroups.com
            Subject: RE: [SQLQueriesNoCode] Order if some order by fields are null

            NULL values will order before non-null values.
            You can use various methods to control ordering, such as ISNULL().


            Regards,

            Arnie Rowland, MVP (SQL Server)
          • Arnie Rowland
            While the forum may be vendor neutral, the products are not. There are slight differences in how vendors implement ANSI standards. Regards, Arnie Rowland, MVP
            Message 5 of 8 , Jul 12, 2011
              While the forum may be vendor neutral, the products are not.
              There are slight differences in how vendors implement ANSI standards.


              Regards,

              Arnie Rowland, MVP (SQL Server)

              "You cannot do a kindness too soon because you never know how soon it
              will be too late."
              -Ralph Waldo Emerson




              -----Original Message-----
              From: SQLQueriesNoCode@yahoogroups.com
              [mailto:SQLQueriesNoCode@yahoogroups.com] On Behalf Of Rob Richardson
              Sent: Tuesday, July 12, 2011 8:51 AM
              To: SQLQueriesNoCode@yahoogroups.com
              Subject: RE: [SQLQueriesNoCode] Order if some order by fields are null

              When I ran a query using the original form in PostgreSQL, the null
              values were sorted after the non-null values.

              I did not mention my platform because I thought this list was supposed
              to be platform-agnostic.

              RobR

              -----Original Message-----
              From: SQLQueriesNoCode@yahoogroups.com
              [mailto:SQLQueriesNoCode@yahoogroups.com] On Behalf Of Arnie Rowland
              Sent: Tuesday, July 12, 2011 11:43 AM
              To: SQLQueriesNoCode@yahoogroups.com
              Subject: RE: [SQLQueriesNoCode] Order if some order by fields are null

              NULL values will order before non-null values.
              You can use various methods to control ordering, such as ISNULL().


              Regards,

              Arnie Rowland, MVP (SQL Server)


              ------------------------------------

              Yahoo! Groups Links
            Your message has been successfully submitted and would be delivered to recipients shortly.