How to merge(columns) outputs of two SELECT statements in oracle sql?
If you have elaborated queries (not just tables to join), you may try using with
construction
with
Query1 as ( -- <- Put your 1st Query text here
select A,
B
...
),
Query2 as ( -- <- Put your 2nd Query text here
select B,
C
...
)
select Query1.A,
Query1.B,
Query2.C
from Query1,
Query2
where Query1.B = Query2.B
If your case is not that complicated, e.g. both Query1 and Query2 are in fact tables, say Table1
and Table2
you can do well with a simpler solution:
select Table1.A,
Table1.B,
Table2.C
from Table1,
Table2
where Table1.B = table2.B
Kailash Akilesh
Updated on June 13, 2022Comments
-
Kailash Akilesh almost 2 years
I have two Select queries.
The first Select query gives the output which has two columns viz.
A B ------ 1 2 3 4 5 6 7 8
The second Select query given the output which as two columns viz Column B and Column C. All the values in Column B of this select statement matches the values of Column B of the first Select statement.i.e
B C ------ 2 25 4 50 6 30 8 50
Now, I need to merge the outputs of the above two Select queries. i.e
A B C ---------- 1 2 25 3 4 50 5 6 30 7 8 50
I cannot use views to store the output of the two select queries. I need to use the Column B in both select queries to merge. However, I am not able to figure out how to go about it.