Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2004
    Posts
    9

    Unanswered: Nice problem: How to combine different columns into a table

    It's rather easy to combine resultset from the same table structure...we can either insert the entries or union the results.

    But let's say you select different columns from different tables and want to combine them to form a new table, how would you do it (assuming you can't join those tables since they are not related), assuming they all return the same number of rows.

    select col1 from table1
    go
    select col2 from table2
    go

    Now I want to combine them so table3 is made of col1 and col2.

  2. #2
    Join Date
    Feb 2002
    Posts
    2,232
    Go into more detail as to what you are trying to do - if I understand what you are attempting to do, how do you guarantee the relationship between col1 and col2, so that when an insert into table3 occurs you have the correct col1 and col2 together ?

  3. #3
    Join Date
    Jan 2004
    Posts
    9
    Originally posted by rnealejr
    Go into more detail as to what you are trying to do - if I understand what you are attempting to do, how do you guarantee the relationship between col1 and col2, so that when an insert into table3 occurs you have the correct col1 and col2 together ?
    I basically go through gathering a list of statistical info for all users.
    So say I have 10 users. I do one pass of some rather complex queries to get the data for first column. Then I do another pass for another column. Now I want to combine them all into one table.

    There is no need to guarantee the relationship between columns, this is merely for reporting purposes so once combined there will never be row insertion to the table ever.

    e.g.

    User [dataset 1] [dataset 2] [dataset 3]
    1 10 20 2
    2 23 30 4


    Thanks!

  4. #4
    Join Date
    Sep 2003
    Posts
    39
    Originally posted by waspfish
    I basically go through gathering a list of statistical info for all users.
    So say I have 10 users. I do one pass of some rather complex queries to get the data for first column. Then I do another pass for another column. Now I want to combine them all into one table.

    There is no need to guarantee the relationship between columns, this is merely for reporting purposes so once combined there will never be row insertion to the table ever.

    e.g.

    User [dataset 1] [dataset 2] [dataset 3]
    1 10 20 2
    2 23 30 4


    Thanks!
    1. Create an @table with an identity. Fill that table.
    2. Create another @table with an identity. Fill that with the second table.
    3. Query both tables and relate them using their identities.

  5. #5
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    you mean something like this >>>

    Code:
    select id, (select count(*) from sysobjects), (select max(id) from sysindexes) from syscolumns
    Get yourself a copy of the The Holy Book

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

Posting Permissions

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