How can I combine two tables with different data and set value for CompanyC
to all data in Table 2 even there is no relationship of CompanyC
on Table2.
Table 1: Table 2:
company jobs company jobs emp_name
----------------------------------- ---------------------------------
CompanyA IT CompanyA IT John
CompanyB Business CompanyB Business Mike
CompanyC Engineer
And the Result Table would be like:
company jobs emp_name
------------------------------------------
CompanyA IT John
CompanyC Engineer John
CompanyB Business Mike
CompanyC Engineer Mike
I already tried this and it is working but the problem is since CompanyC has no data on Table 2. The result will be null.
select coalesce(t1.company, t2.company)
t1.jobs, t2.emp_name
from table1 t1 full outer join
table2 t2
on t2.name = t1.name;
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…