SQL - merge the contents of two tables into one table / view

I need to create a view (or table) that contains values ​​of n rows taken from two different tables having the same structure. For instance:

table europe

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

USA table

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

The combined view should be like this:

WORLD table

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

is it possible? if so how?

Thanks in advance for your help, best regards

+5
source share
2 answers

if you just want to get a result than try a join request

SELECT id,name,Country FROM dbo.Europe
UNION
SELECT id,name,Country FROM dbo.USA
+8
source

You can create a reusable join type like this:

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

(name it whatever, instead allcountries)

then just:

select * from allcountries;
+3
source

All Articles