I have 2 databases (database1 and database2).
- database1 has table1 with field id
- database2 has table2 with field id
Now how do i perform leftJoin(as shown below) using Slick?
SELECT tb1.`id`
FROM `database1`.`table1` t1
LEFT JOIN `database1`.`table2` t2 ON t1.`id`=t2.`id`
I may be wrong here but most existing relational databases don't allow you to span multiple databases within single operation. However, what you showed above is easily achievable by using
schema
(and I strongly believe this is what you want to really achieve -judging by the SQL you pasted).Let's have an example. Let's assume we have two tables defined within our
Slick
-related code as follows:Doing following query:
will generate following SQL:
If I however change my table definition to:
and this
Notice that I added one parameter -
_schemaName
- which indicates that particular table should be prefixed by specified schema.I will have (same Slick query) following SQL generated now:
which seems to be precisely what you want to achieve.