join two tables from two different databases

I have two databases - same server
I need to create a join of datasource1.customer and datasource2.payments - joined on an account number.
How would I do this .
TagomAsked:
Who is Participating?
 
Jim HornConnect With a Mentor Microsoft SQL Server Developer, Architect, and AuthorCommented:
Just spell out the database_name.schema.object_name

SELECT c.*
FROM datasource1.dbo.customer c
   JOIN datasource2.dbo.payments p on c.id = p.customer_id

or if the default schema is dbo, just do 'dot-dot', although this is not considered a best practice

SELECT c.*
FROM datasource1..customer c
   JOIN datasource2..payments p on c.id = p.customer_id
0
 
Barry62Connect With a Mentor Commented:
SELECT datasource1.table1.customer,datasource1.table1.accountnum, datasource2.table2.payments FROM datasource1.table1 inner join datasource2.table2  ON datasource1.table1.accountnum=datasource2.table2.accountnum
0
 
Vijaya Reddy Pinnapa ReddyCommented:
SELECT datasource1.customer.field1,datasource1.customer.field2,datasource1.customer.field3,datasource1.customer.field4*, datasource2.payments *
FROM datasource1.customer INNER JOIN Orders ON datasource1.customerCustomerNo =
datasource2.payments..CustomerNO
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the split.  Good luck with your project.  -Jim
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.