SQL - merge two tables content in one table/view

21,847

Solution 1

if you just want to result than try union query

SELECT id,name,Country FROM dbo.Europe
UNION
SELECT id,name,Country FROM dbo.USA

Solution 2

You can create a reusable view of the union like so:

create view allcountries as select * from usa union select * from world;

(name it anything you like in place of allcountries)

then just:

select * from allcountries;
Share:
21,847
BeNdErR
Author by

BeNdErR

this is not the profile you are looking for. SOreadytohelp

Updated on May 01, 2020

Comments

  • BeNdErR
    BeNdErR about 4 years

    I need to create a view (or a table) that holds n row values, taken from two different tables that have the same structure. For example:

    table Europe

    id    name        Country
    ----------------------------
    1     Franz       Germany
    2     Alberto     Italy
    3     Miguel      Spain
    

    table USA

    id    name        Country
    ----------------------------
    1     John        USA
    2     Matthew     USA
    

    The merged view has to be like this:

    table WORLD

    id    name        Country
    ----------------------------
    1     John        USA
    2     Matthew     USA
    1     Franz       Germany
    2     Alberto     Italy
    3     Miguel      Spain
    

    it's possible? if it is, how?

    Thanks in advance for your help, best regards