How can I combine two tables with different data and set value for CompanyC
to all data in Table 2 and CompanyD
has no relationship on Table 1. I want the Company C
to set all data on Table 2.
T1: T2:
company jobs emp_id company jobs emp_name
----------------------------------- -------------------------------------
CompanyA IT 1 CompanyA IT John
CompanyB Business 2 CompanyB Business Mike
CompanyC Engineer 3 CompanyD Nurse Mitch
And the result table would be like:
emp_id company jobs emp_name
----------------------------------------------
1 CompanyA IT John
1 CompanyC Engineer John
2 CompanyB Business Mike
2 CompanyC Engineer Mike
3 CompanyD Nurse Mitch
3 CompanyC Engineer Mitch
This is what I've tried
SELECT t2.emp_id, coalesce(t1.company_name, t2.company_name) AS company_name,
coalesce(t1.jobs, t2.jobs) AS jobs,
t2.emp_name,
FROM Table1 t1
FULL OUTER JOIN
Table2 t2 ON t2.company = t1.company AND t2.jobs = t1.jobs
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…