Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2004
    Posts
    31

    Unanswered: Order by problem

    Hi there...

    If I have a table with two differnet DateTime variables, and I want to order the hits in date order. The problem is that I want to order them depending of wich of theese two columns are the highest(eg. latest date)

    ex:
    id | date_1 | date_2
    ------------------
    1 | 1991 | 2001
    2 | 2002 | 1991
    3 | 1993 | 1992

    should result in(highest first):
    id
    ---
    2
    1
    3

    How would I do this?

  2. #2
    Join Date
    Jan 2003
    Location
    Nottinghamshire, UK
    Posts
    364
    You Could Try

    Select Date_1 as UDate FROM table
    UNION
    Select Date_2 as UDate FROM table
    ORDER By UDate DESC
    "Everything should be made as simple as possible, but not simpler." - Albert Einstein
    "Everything should be made as complex as possible, so I look Cleverer." - Application Developer

  3. #3
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    ORDER BY case when date1 > date2 then date1 else date2 end
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  4. #4
    Join Date
    Nov 2003
    Posts
    94
    Quote Originally Posted by blindman
    ORDER BY case when date1 > date2 then date1 else date2 end
    ORDER BY case when d1 > d2 then d1 else d2 end DESC

Posting Permissions

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