2013-07-27 66 views

回答

2

你可以使用UNION

SELECT Col_1 AS Col_3 
FROM Numbers 

UNION 

SELECT Col_2 AS Col_3 
FROM Numbers 
1

如果你只想要兩個表中的獨特價值,不介意掃描表兩次,然後:

select col1 as col3 
from numbers 
union 
select col2 
from numbers 

如果你想保留所有的值,然後使用UNION ALL:

select col1 as col3 
from numbers 
union all 
select col2 
from numbers 

如果表是足夠大,使得避免兩個掃描將是優選的:

with cte_two_rows as (
    select 1 col from dual union all 
    select 2 col from dual) 
select 
    case col 
    when 1 then col1 
    when 2 then col2 
    end col3 
from 
    numbers cross join cte_two_rows 
相關問題