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;
精彩评论