Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2006
    Posts
    1

    Unanswered: Join 2 columns in 1 table

    I have a table with 5 columns, 2 columns of them are "datetime" field (starttime and endtime).
    example:
    id starttime endtime
    -------------------------------------------------------------------
    1 2006-02-24 01:00:00 2006-02-24 02:00:00
    2 2006-02-24 03:00:00 2006-02-24 04:00:00
    3 2006-02-24 05:00:00 2006-02-24 06:00:00
    4 2006-02-24 07:00:00 2006-02-24 08:00:00

    I want to the output all data sorting by the time of both starttime and endtime.

    time
    -------------------------------
    2006-02-24 01:00:00
    2006-02-24 02:00:00
    2006-02-24 03:00:00
    2006-02-24 04:00:00
    2006-02-24 05:00:00
    2006-02-24 06:00:00
    2006-02-24 07:00:00
    2006-02-24 08:00:00



    How to write the query??

    Thank you

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    ( select starttime as time from daTable )
    union all
    ( select endtime from daTable )
    order by 1
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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