Can I join data from 2 different DB2 databases? (Like SQL Server linked databases)

萝らか妹 提交于 2020-01-11 05:04:09

问题


I'm enhancing an existing java application. There is data in 2 different DB2 databases. The app already gets data from 2 different databases, but it always does a lookup from one and then the other. Is there a way to join data from 2 different DB2 databases using one SQL SELECT?

This is what I tried:

CREATE ALIAS remote_orders FOR remote_db.schema.orders;

select *
from myid.remote_orders a
inner join local_schema.parts b on (a.key = b.key)
with ur FETCH FIRST 200 ROWS ONLY

I get this error:

STATEMENT REFERENCE TO REMOTE OBJECT IS INVALID. SQLCODE=-512, SQLSTATE=56023, DRIVER=4.14.113

Can I do something with a temp table? I can run this select with no errors, but it does not help me... (yet)

select *
from myid.remote_orders
with ur FETCH FIRST 200 ROWS ONLY

EDIT:

A DB2 Temp Table might help. I was able to create one. Now I need to (go to bed) and try selecting into it and THEN doing my join.


回答1:


Use fully qualified name <database>.<user/schema>.<tablename>

something like:

select *
from DB1.myid.remote_orders a
inner join DB2.local_schema.parts b on (a.key = b.key)
with ur FETCH FIRST 200 ROWS ONLY


来源:https://stackoverflow.com/questions/15126560/can-i-join-data-from-2-different-db2-databases-like-sql-server-linked-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!