合并表并更新一列

时间:2011-05-11 05:40:37

标签: sql oracle

我正在使用Oracle,我需要合并两个查询,但我想在最后添加一个列,显示我将值设置为“query2”,这意味着它是来自query2的结果。

到目前为止有我的例子

select t1.* , t2.* , 0 isdefault
  from table1 t1, table2 t2 
 where ....                  
union           
select t1.*,t2.*, t3.isdefault    
  from table1 t1, table2 t2, table3 t3
 where ... 
   and t3.inactive = 0;

1 个答案:

答案 0 :(得分:0)

静态定义值,就像您为isdefault提供的那样:

SELECT t1.*, t2.*, 0 isdefault, 'query1' AS whichQuery
  FROM table1 t1, 
       table2 t2 
 WHERE ...
UNION           
SELECT t1.*,t2.*, t3.isdefault, 'query2' AS whichQuery
  FROM table1 t1, 
       table2 t2,
       table3 t3
 WHERE ... 
   AND t3.inactive = 0;