2015-11-05 128 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

完美,这是正是我需要的:)谢谢 –