how do write a sql query that joins a table in one database to a table located in another database in the same SQL Server

Manuel Pineda 0 Reputation points
2024-08-07T13:25:09.25+00:00

how do write a sql query that joins a table in one database to a table located in another database in the same SQL Server

SQL Server Other
{count} votes

1 answer

Sort by: Most helpful
  1. Zahid Butt 961 Reputation points
    2024-08-07T13:42:45.66+00:00

    Hi,

    Here is sample select query:

    select e.emp_no,e.emp_name,e2.added_date
    
    from Database1.dbo.Table1 e
    
    inner join Database2.dbo.Table2 e2 on e.id=e2.id
    
    

    Further you may get help from below link:

    https://datatofish.com/join-tables-different-databases-sql-server/#:~:text=To%20join%20tables%20from%20two%20different%20databases%20in,tb_1%20JOIN%20%5Bdatabase_2%5D.%5Btable_schema%5D.%5Btable_name_2%5D%20tb_2%20ON%20tb_1.id%20%3D%20tb_2.id


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.