开发者

Updating Value in a table

开发者 https://www.devze.com 2023-01-20 02:19 出处:网络
I want to achieve this .. update Table_A c set c.Column1 = (select d.column1 - b.column2 from Table_B d, Table_A b

I want to achieve this ..

update Table_A c 
set c.Column1 = 
(select d.column1 - b.column2
from Table_B d, Table_A b
where b.primary_key = d.primar开发者_如何学JAVAy_key)

But for outer query there is no primary key clause i have added.. How do i achieve it


It's very unclear what you want to do.

Also your aliases are confusing. If there is a Table_a and a Table_b don't name Table_a b.

update table_a a1
   set a1.column1 = (select b.column1 - a2.column2
                       from table_b b,
                            table_a a2   
                      where b.primary_key = a2.primary_key)


Your question isn't clear, but I wonder if you meant to do a correlated subquery like this:

update Table_A a 
set a.Column1 = 
(select b.column1 - a.column2
from Table_B b
where b.primary_key = a.primary_key)

Note that the alias "a" in the subquery refers to the row that is being updated in the main query.

0

精彩评论

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