2013-07-27 65 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 
相关问题