2015-11-05 173 views
-1

我有兩個子查詢與兩個不同表中的相同列,我想用兩個子查詢中的行轉入視圖。合併2個子查詢

(SELECT one AS a, two AS b FROM table_a WHERE condition_a=true) 
(SELECT tree AS a, four AS b FROM table_b WHERE condition_b=true) 

(For the example lets assume that all data is VARCHAR(10)) 

從這些2個查詢我想要與列「A」和「B」,與所有來自查詢結果的視圖。

這可能嗎?如果這是我該怎麼做?

回答

2

使用union all

create view v_ab as 
    SELECT one AS a, two AS b FROM table_a WHERE condition_a=true 
    union all 
    SELECT tree AS a, four AS b FROM table_b WHERE condition_b=true; 
+0

完美,這是正是我需要的:)謝謝 –