Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2008
    Posts
    7

    Unanswered: Merge DIFFERENT TABLES into ONE - HELP PLZ

    Hi,
    I am very new to Sybase I have a very basic Question.

    How do I merge tables resulted from Select queries into one? One after the other would do...

    E.G
    SELECT t1.Date, t1.Price FROM T1 WHERE ....

    And another table that Iget from another select query

    SELECR t2.DATE, t2.Price FROM T2 WHERE....

    KNOWING THAT T1 and T2 have many different columns... so UNION ALL wont work....

    Many thanks for your help!

  2. #2
    Join Date
    Apr 2008
    Location
    Iasi, Romania
    Posts
    561
    Provided Answers: 2
    If your SELECT statements have only the common columns, UNION ALL will work.

  3. #3
    Join Date
    Nov 2008
    Posts
    7
    unfortunately it doesnt have the same columns....

  4. #4
    Join Date
    Nov 2008
    Posts
    7
    I probably didnt express myself properly but this is what I am doing

    QUERY1: SELECT T1.DATE_A, T1.PRICE_A FROM T1 WHERE ...

    QUERY2: SELECT T2.DATE_B, T2.PRICE_B FROM T2 WHERE ...

    so the columns I am putting together do not have the same name....but the same format.

    I would like to have both of these results in one table.

    I am doing this in SYBASE, I understand I could have done this in Oracle with a procedure ... maybe something along those lines?

    Many thanks

  5. #5
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    As long as the columns have the same data type you can use union all
    SELECT T1.DATE_A, T1.PRICE_A FROM T1 WHERE ...
    union all
    SELECT T2.DATE_B, T2.PRICE_B FROM T2 WHERE ...

  6. #6
    Join Date
    Apr 2008
    Location
    Iasi, Romania
    Posts
    561
    Provided Answers: 2
    with this:

    Query2: SELECT t2.date_B AS date_A, t2.price_B AS price_A FROM T2 ...

    the columns will have the same name, too.

  7. #7
    Join Date
    Nov 2008
    Posts
    7
    that was dumb of me, that worked thanks mate.

Posting Permissions

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