Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2003
    Posts
    35

    Question Unanswered: ORDER BY ... DESC and NULL VALUES question (sql plus)

    I was wondering how to use ORDER BY .... DESC, and not have NULL values appear as the first row.

    In context to what Im doing, I have a query that displays total sales month-by-month of products and my final column is total sales of that product for a specified year. Im using ORDER BY total sales DESC to sort the results. THere is one product that hadn't sold anything for a given year, and so its value for total sales is NULL. Using ORDER BY total sales DESC, places that row first.

    There isn't any other clause I can put in the ORDER BY expression so that null values are last is there?

    Other wise, what can I do to get around this?
    "My Idea is that everyone should be required to use small fonts. That way we'll save disk space.
    ~Asok.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,296
    case when column is null then column value = 0
    or
    replace(column, nvl, 0)

    post your query.
    - The_Duck
    you can lead someone to something but they will never learn anything ...

  3. #3
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: ORDER BY ... DESC and NULL VALUES question (sql plus)

    ORDER BY ... DESC NULLS LAST;

  4. #4
    Join Date
    Jul 2003
    Posts
    2,296

    Re: ORDER BY ... DESC and NULL VALUES question (sql plus)

    Originally posted by andrewst
    ORDER BY ... DESC NULLS LAST;
    didn't know about that one. nice!
    - The_Duck
    you can lead someone to something but they will never learn anything ...

  5. #5
    Join Date
    Jan 2003
    Posts
    35
    VERY NICE THANK YOU!!
    "My Idea is that everyone should be required to use small fonts. That way we'll save disk space.
    ~Asok.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •