Oracle SQL - 有 2 个 table,并希望根据第一个 table 的 ID 值从第二个 table 找到发货和交付代码

Oracle SQL - have 2 tables and want to find the ship from and delivery to codes from 2nd table based on ID values from first table

我有 2 张桌子。

Table A 有商品代码,org_id 发货自,org_id 送达

Table B 已将 org_id 映射到 org_code

我想做这样的事情:

select a.item_code, b.org_code AS "ship from", b.org_code as "deliver to"
from table a, table b
where a.org_id = b.org_id

有人可以帮帮我吗?我怎样才能做这样的事情?

您需要两个连接:

select a.item_code, bs.org_code AS "ship from", bt.org_code as "deliver to"
from a left join
     b bs
     on a.ship_from = bs.org_id left join
     b bt
     on a.ship_to = bt.org_id;

如果某些值是 NULL 或没有匹配值,则使用 left join