Jackelll Jackelll - 5 months ago 52
SQL Question

Outer Join merge column

My current query involves joining multiple tables and I'm using full outer join for it. However, my query resulted in multiple columns of the same name. How do I combine the result into one single column?

Below is an example of my query

Select table1.a,table1.b AS "chocolate",table2.b AS "chocolate"
from table1
full outer join table2 ON table1.c = table2.c
WHERE table1.a > 100

However the column will result in


Thanks in advance!

enter image description here
EDIT: basically I'm just trying to combine inp_pages and art_pages in a single column

Answer Source

According to the attached screenshot, it seems as though only one of the two columns can have a value, and the other is always null. If this is true, you could coalesce the results into a single column:

SELECT          table1.a, COALESCE(table1.b, table2.b) AS "chocolate"
FROM            table1
FULL OUTER JOIN table2 ON table1.c = table2.c
WHERE           table1.a > 100
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download