TB1, TB2, TB3 are in one database on the server and TB4 is on another database.
The column information needed for the join are as follows:
- TB1 – column a1, b2.
- TB2 – column a2, b2, c3.
- TB3 – column a3.
- TB4 – column a4.
TB1, TB2, TB3 are related by ID
TB1’s ID is the primary key and the foreign keys in TB2, TB3 and TB4
I am using SQL Server Management Studio
Code:
select ID
from TB1, TB2, TB3
where TB1.ID = TB2.TB1.ID
You can link them like this (don’t forget to put the relation that you missed to say):
Also replace
db1anddb2by the database names on which each table is present.One final note, your code it’s giving redundant information because you didn’t make all the restrictions. So, a cartesian product is produced.