BeNdErR
BeNdErR

Reputation: 17929

SQL - merge two tables content in one table/view

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

Upvotes: 5

Views: 22621

Answers (2)

Bhavin Chauhan
Bhavin Chauhan

Reputation: 2010

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

Upvotes: 9

Paul Roub
Paul Roub

Reputation: 36438

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;

Upvotes: 3

Related Questions