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
SQL JOIN. A JOIN clause is used to combine rows from two or more tables, based on a related column between them.
A view that combines data from multiple tables enables you to show relevant information in multiple tables together. You can create a view that combines data from two or more tables by naming more than one table in the FROM clause.
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
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With