views:

33

answers:

2

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.primary_key)

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

A: 

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)
Rene
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 and a1.key = a2.key) Thanks for your help.. I understood the problem
Khyati
Won't this do? update table_a a1 set a1.column1 = (select b.column1 - a1.column2 from table_b b where b.primary_key = a1.primary_key)
Rene
A: 

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 qeury.

Tony Andrews