I have two tables table A and table B .
Table A contain column colA which contains values (1,3,5,7)
Table B contain column colB which contains values (2,4,6,8)
My query is how can i combin开发者_开发百科e these two tables and get one column with output (1,2,3,4,5,6,7,8)
I am using oracle 10g
Maybe:
SELECT colA FROM A
UNION ALL
SELECT colB FROM B
If you care about order and unicity:
SELECT colA FROM A
UNION
SELECT colB FROM B
This would be avail...
SELECT * FROM
(
SELECT colA AS TEMP_COL FROM A
UNION
SELECT colB AS TEMP_COL FROM B
)
ORDER BY TEMP_COL
with A as (
select 1 as cola from dual
union all
select 2 as cola from dual
union all
select 3 as cola from dual
),
B as (
select 4 as colb from dual
union all
select 5 as colb from dual
union all
select 6 as colb from dual
)
select substr(SYS_CONNECT_BY_PATH(colab, ','),2) col_list
from
(
select colab,
count(*) over (partition by 1) as cnt,
ROW_NUMBER () OVER ( partition by 1 order by colab) seq
from
(
select cola as colab from A
union all
select colb as colab from B
)
)
where cnt = seq
start with seq = 1
connect by prior seq + 1 = seq
or
select
rtrim (xmlagg (xmlelement (el, colab || ',')).extract ('//text()'), ',') col_list
from
(
select cola as colab from A
union all
select colb as colab from B
)
Regards..
For 10g, try -
SELECT WMSYS.WM_CONCAT(
SELECT Cola as Colab FROM A
UNION ALL
SELECT Colb AS Colab FROM B
) FROM DUAL;
精彩评论