I have three tables. Table1 is in DB1 and both table2 and table3 is in DB2 as mentioned below:
Table1 in DB1: customerId, accountNumber
Table2 in DB2: customerId, accountNumber, id
Table3 in DB2: id, name, country
I want to get name and country from table3 based on customerId and accountNumber from table1. the tables are related as mentioned above. Tables are not having any mapping, just the columns are same.
I am using spring JPA and MySql.
Could anyone please help how to perform a join query on above 3 tables across database in spring JPA (in JPARepository class).
I want to have a join query like in repo class to run:
select distinct d2t3.id from DB1.Table1 d1t1, DB2.Table2 d2t2, DB2.Table3 d2t3
where d1t1.customerid=d2t2.customerid
and d1t1.accountNumber=d2t2.accountNumber
and d2t2.id=d2t3.id;