我有两个表A和表B.
表A包含列colA,其中包含值(1,3,5,7)
表B包含列colB,其中包含值(2,4,6,8)
我的查询是如何组合这两个表并获得一列输出(1,2,3,4,5,6,7,8)
我正在使用oracle 10g
答案 0 :(得分:6)
也许:
SELECT colA FROM A
UNION ALL
SELECT colB FROM B
如果你关心秩序和单一性:
SELECT colA FROM A
UNION
SELECT colB FROM B
答案 1 :(得分:0)
这会有用......
SELECT * FROM
(
SELECT colA AS TEMP_COL FROM A
UNION
SELECT colB AS TEMP_COL FROM B
)
ORDER BY TEMP_COL
答案 2 :(得分:0)
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
或
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
)
此致..
答案 3 :(得分:-1)
对于10g,尝试 -
SELECT WMSYS.WM_CONCAT(
SELECT Cola as Colab FROM A
UNION ALL
SELECT Colb AS Colab FROM B
) FROM DUAL;