Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ligonsker's avatar

Is it possible to join 2 tables from the same server but from 2 different connections (databases)?

Hello,

Is it possible to join 2 tables with different connections? i.e. each connection has its own DB with its username and password but they're on the same server.

The first default connection in the database.php file is called conn1 and the second is conn2

Edit: I am using SQL Server (and each database is called "object")

Thanks

0 likes
2 replies
tangtang's avatar

@ligonsker

yes it's possible, but why two database if in same server. isn't it make more complex ?

this is standar for join to another table in native

SELECT
	a.var1, a.var2, a.var3, ...
FROM
	database1.table1 a
JOIN
	database2.table2 b

you can do it in laravel with specify the connection this two different database in database.php

Please or to participate in this conversation.