Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2006
    Posts
    111

    Unanswered: Union 2 Temp Tables

    I have 2 temporary tables from a previous operation, Tab1 and Tab2, with the same dimensions. How do I create a third table Tab3 with the same dimensions containing the the combined rows of the 2 previous tables? TIA!

    Tab1
    Col1 Col2 Col3
    A1 B1 C1
    A2 B2 C2

    Tab2
    Col1 Col2 Col3
    X1 Y1 Z1
    X2 Y2 Z2
    X3 Y3 Z3

    After the required sql operation I should have

    Tab3
    Col1 Col2 Col3
    A1 B1 C1
    A2 B2 C2
    X1 Y1 Z1
    X2 Y2 Z2
    X3 Y3 Z3

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Maybe I am missing something but what are you struggling with? Which bit is difficult?

  3. #3
    Join Date
    Jul 2006
    Posts
    111
    if i have the following:

    select
    *
    from
    Tab1

    UNION

    select
    *
    from
    Tab2

    I will have the result but I don't know how to go about inserting this result set in another temporary table, Tab3 in this case.

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    INSERT INTO Tab3
    SELECT *
    FROM ......
    ....
    ....

  5. #5
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    BTW - use UNION ALL if there can be no duplicates or you don't mind duplicates. More efficient.

  6. #6
    Join Date
    Jul 2006
    Posts
    111
    i swear your post i tried earlier but got an error... maybe i'm tired its 1am here been up since 7 am either that or must be the noodles... zzzzzzzz

    thanks btw...

  7. #7
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Let us know the error text if it happens again

  8. #8
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    dimension.....

    I like that word...it's like you know something

    buzz words are always fun
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

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