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 ?
Eprs_AdminSystem ArchitectAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vitor MontalvãoMSSQL Senior EngineerCommented:
Yes. You can do it by creating a Linked Server or using the OPENROWSET function to retrieve the data from the remote server.
Jason clarkDBA FreelancerCommented:
The best way I can think of to accomplish this is via "sp_addlinkedserver". You must be sure that whatever account you use to add the link via "sp_addlinkedsrvlogin" has permissions to the table you're joining, but then once the link is established, you can call the server by name, i.e.:

SELECT *
FROM server1table
    INNER JOIN server2.database.dbo.server2table

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KCTechNetCommented:
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

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Software

From novice to tech pro — start learning today.