在oracle中使用一个表连接两个表

时间:2015-01-06 06:18:31

标签: oracle

我有一张表pa_master_detailslov_details

pa_master_details表格中,我有role_comp_emp_final_ratingrole_comp_lm_final_rating列。

lov_details表中,我的列评分为lov_valuelov_text_en

我需要将role_comp_emp_final_rating加入lov_value列,以获取lov_text_en 根据此lov_value,我需要在lov_text_en表格中显示lov_details

所以我写了一个这样的查询,得到了emp评分的结果:

SELECT p.employee_number,
       p.role_comp_emp_final_rating,
       lov_text_en,
       p.role_comp_lm_final_rating
FROM pa_master_details P, lov_details L
WHERE p.role_comp_emp_final_rating = l.lov_value
AND p.employee_number = 34570

同样,我需要通过加入lov_text_en表格显示role_comp_lm_final_rating lov_details role_comp_lm_final_rating lov_value在同一查询中。{/ p>

我该怎么做?

1 个答案:

答案 0 :(得分:0)

我认为这就是你所要求的:

SELECT p.employee_number,
       p.role_comp_emp_final_rating,
       lemp.lov_text_en AS "emp_lov_text",
       llm.lov_text_en AS "lm_lov_text",
       p.role_comp_lm_final_rating
FROM pa_master_details p
JOIN (SELECT lov_text FROM lov_details) lemp ON p.role_comp_emp_final_rating = lemp.lov_value
JOIN (SELECT lov_text FROM lov_details) llm  ON p.role_comp_lm_final_rating  = llm.lov_value
WHERE p.employee_number = 34570