查询两个表JOIN操作

时间:2015-06-29 11:09:04

标签: oracle11g

表格:1

EMP_ID      DEPT    BATCH_CODE      DEP_CODE
1234        IT          B4            D1
4567        DESIGN      B5            D2
1232        MARKETING   B6            D3

EMP_ID是表1中的PK

表格:2

CODE        DESCRITPION
B4           IT DEVELOPMENT
D1           TECHNICAL DESING
B5           SUPPORT
D2           DB DESIGNER
B6           SALES
D3           CASH

预期输出

BATCH CODE      Batch Description   Dep_Code    Dep_Descritpion
B4                IT DEVELOPMENT     D1          TECHNICAL DESING
B5                SUPPORT            D2          DB DESIGNER
B6                SALES              D3          CASH

有人可以帮我构建一个查询来获取table1和table2值的预期输出吗?

1 个答案:

答案 0 :(得分:0)

尝试此查询

select b.CODE BATCH_CODE,b.Description BATCH_Description,
  c.code Dep_Code,c.Description Dep_Descritpion
from table1 a
join table2 b on a.BATCH_CODE=b.CODE
join table2 c on a.DEP_CODE=c.CODE