Concatenate result sets

  • How Can I concatenate two or more result set to make it single result set. if number of rows are same.

    for ex.

    first Result set is

    aaa

    bbb

    ccc

    ddd

    eee

    Second is

    111

    222

    333

    444

    555

    I want to get output

    aaa 111

    bbb 222

    ccc 333

    ddd 444

    eee 555

    Vaibhav K Tiwari
    To walk fast walk alone
    To walk far walk together

  • Add some ID with Identity (1,1) in two tables then write this SELECT TABLE1.CHARS, TABLE2.NUMBERS FROM TABLE1, TABLE2 WHERE TABLE1.ID = TABLE2.ID

    ============================================================
    SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
    http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]

  • Thanks for the suggestion and got the hint i can do it by row_number function.

    Thanks again

    Vaibhav K Tiwari
    To walk fast walk alone
    To walk far walk together

  • vaibhav.tiwari (3/30/2010)


    Thanks for the suggestion and got the hint i can do it by row_number function.

    Thanks again

    Let us know how you did!?

    ============================================================
    SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
    http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]

  • Dugi (3/30/2010)


    vaibhav.tiwari (3/30/2010)


    Thanks for the suggestion and got the hint i can do it by row_number function.

    Thanks again

    Let us know how you did!?

    Something like this -

    CREATE TABLE #tempA (val varchar(10))

    CREATE TABLE #tempB (val varchar(10))

    INSERT INTO #tempA VALUES('aaa')

    INSERT INTO #tempA VALUES('bbb')

    INSERT INTO #tempA VALUES('ccc')

    INSERT INTO #tempA VALUES('ddd')

    INSERT INTO #tempB VALUES('111')

    INSERT INTO #tempB VALUES('222')

    INSERT INTO #tempB VALUES('333')

    INSERT INTO #tempB VALUES('444')

    SELECT a.val, b.val FROM

    ( SELECT val, ROW_NUMBER() OVER (ORDER BY ( SELECT 1 ) ) Seq FROM #tempA ) a

    INNER JOIN

    ( SELECT val, ROW_NUMBER()OVER (ORDER BY ( SELECT 1 ) ) Seq FROM #tempB ) b

    ON a.seq = b.seq

    Vaibhav K Tiwari
    To walk fast walk alone
    To walk far walk together

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply