merge multiple table coloum data in new table

  • in my database ....i have four tables ....every table have mobile coloum ..........

    i want o/p like FOUR table mobile field MERGE in newtable ......

    ex-

    table 'a'

    name mobile

    raju 9876523422

    vamshi 9676768200

    table 'b'

    name mobile

    cas 9876523987

    saxsc 9347543211

    table 'c'

    name mobile

    ramu 9875429000

    fgdhj 9856432111

    table 'd'

    name mobile

    asv 9834256234

    shash 9867598765

    i want table a,b,c,d mobile coloum data merge in newtable ....ouput like below table......

    Mobile

    9876523422

    9676768200

    9876523987

    9347543211

    9834256234

    9867598765

    9875429000

    9856432111

  • shashianireddy 30786 (12/26/2013)


    in my database ....i have four tables ....every table have mobile coloum ..........

    i want o/p like FOUR table mobile field MERGE in newtable ......

    ex-

    table 'a'

    name mobile

    raju 9876523422

    vamshi 9676768200

    table 'b'

    name mobile

    cas 9876523987

    saxsc 9347543211

    table 'c'

    name mobile

    ramu 9875429000

    fgdhj 9856432111

    table 'd'

    name mobile

    asv 9834256234

    shash 9867598765

    i want table a,b,c,d mobile coloum data merge in newtable ....ouput like below table......

    Mobile

    9876523422

    9676768200

    9876523987

    9347543211

    9834256234

    9867598765

    9875429000

    9856432111

    This would just be multiple SELECTs separated by UNION or UNION ALL depending on whether or not you wanted distinct values.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • INSERT INTO NewTable(name,mobile)

    SELECT name,mobile from a UNION ALL

    SELECT name,mobile from b UNION ALL

    SELECT name,mobile from c UNION ALL

    SELECT name,mobile from d

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • For Distinct try like this.

    select a.Number INTO One_Column FROM

    (select Number from Merge_Columns

    UNION

    select Number from Merge_Columns1

    )a

    For whole data from both table try like below.

    select a.Number INTO One_Column FROM

    (select Number from Merge_Columns

    UNION ALL

    select Number from Merge_Columns1

    )a

    Hope this helps.

    Thanks:)

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

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