Nike Yulistia Angreni Nike Yulistia Angreni - 5 months ago 5
SQL Question

How to join multiple condition table in MySql

I have

perf_component_valuation
table :

enter image description here

Then I join it:

SELECT CONCAT(ee.first_name,' ',ee.last_name) as valuated_name,CONCAT(ee.first_name,' ',ee.last_name) as valuator_name from emp_employee as ee
left join perf_component_valuation as pcv on pcv.valuator=ee.employee_id
WHERE pcv.phc_id =49;


And try this one:

SELECT CONCAT(ee.first_name,' ',ee.last_name) as valuated_name,CONCAT(ee.first_name,' ',ee.last_name) as valuator_name from emp_employee as ee
left join perf_component_valuation pcv on pcv.valuator=ee.employee_id
left join perf_component_valuation pcv2 on pcv2.valuated=ee.employee_id
WHERE pcv.phc_id =49;


But it just give me valuator name only,not valuated.This is the result:


enter image description here


The result that i want is:

valuated_name || valuator_name
______________________________
Adni || Arli Ramdhani
Adni || Mohammad Aldo



How can i give another condition on it?

Answer

try joining on to emp_employee twice

SELECT CONCAT(valuated_ee.first_name,' ',valuated_ee.last_name) as valuated_name,CONCAT(valuator_ee.first_name,' ',valuator_ee.last_name) as valuator_name 
from perf_component_valuation as pcv
left join emp_employee as valuated_ee on pcv.valuated=valuated_ee.employee_id
left join emp_employee as valuator_ee on pcv.valuator=valuator_ee.employee_id
WHERE pcv.phc_id =49;
Comments