开发者

merging table and updating one column

I am using Oracle, I need to me开发者_如何学Gorge two queries, but i would like to add one column at the end showing where i set the value to "query2", which mean it was a result coming from query2.

there is my example so far

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;


Statically define the value, like you provided for the 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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜