Link to home
Start Free TrialLog in
Avatar of Eprs_Admin
Eprs_AdminFlag for Austria

asked on

SQL join two tables

Hi Experts,

I have two tables in SQL on two different machines.
Is it possible to join this table into one ?
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Yes. You can do it by creating a Linked Server or using the OPENROWSET function to retrieve the data from the remote server.
ASKER CERTIFIED SOLUTION
Avatar of Jason clark
Jason clark
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Following Vitor Montalvao and Jason clark's comments:

Use linkedserver method: exec addlinkedserver to connect the two databases.
then use this example that works for me:

with 
table1query as
(
  select col1 as col1,col2 as col2 from [server].[database].[dboschema].[tablename]
)
,
tabl2query as
(
  select col1 as col1,col2 as col2 from [otherserver].[otherdatabase].[otherdboschema].[othertablename]
)

select * from table1query
union all
select * from table2query

Open in new window