jgordin
asked on
sql update
i have three tables:
t1 t2 t3
=== === ===
c1 c1 c1
c2 c2 c2
c3
c4
c5
i need to update t2.c2 = t3.c2
for the cases
when t1.c1 = t2.c1 and t2.c2 = t3.c2 and t1.c4 = "ABC' and t1.c5 = "XYZ"
t1 t2 t3
=== === ===
c1 c1 c1
c2 c2 c2
c3
c4
c5
i need to update t2.c2 = t3.c2
for the cases
when t1.c1 = t2.c1 and t2.c2 = t3.c2 and t1.c4 = "ABC' and t1.c5 = "XYZ"
ASKER
the proposed solution doesnt work. correction to the problem:
t1 t2 t3
=== === ===
c1 c1 c1
c2 c2 c2
c3
c4
c5
i need to update t2.c2 = t3.c2
for the cases
when t1.c1 = t2.c1 (t1.c1 will have two rows in t2.c1)
t1 t2 t3
== ============ ===========
c1 c2 c3 c1 c2 c3 c1 c2
-- --------- -------------- --------------
abc1 abc1| xyz1| xyz1 mnp
abc2 abc1| xyz2| xyz4
abc2 abc2| XYz3|
abc2
t1.abc1, t1.abc2, and t1.abc3 is c1 above in table1
t2.abc1, t2.abc1 .... is c1 above in table2
i need to update column2 (t2.c2) of table1 = with value in column 2 in table 3 in case when
t1.c1 = t2.c1 and t2.c3 = t3.c1 (if t1.c1 = t2.c1 but t2.c3 doesnt have value in t3.c1 then
no update) and t1.c3 = "abc' (additional condition).
for above example i would expect MNP appear in t1.c2 (one
t1 t2 t3
== ============ ===========
c1 c2 c3 c1 c2 c3 c1 c2
-- --
abc1 abc abc1| MNP xyz1| xyz1 MNP
abc2 ppp abc1| xyz2| xyz4
abc2 abc2| xyzz3|
abc2
t1 t2 t3
=== === ===
c1 c1 c1
c2 c2 c2
c3
c4
c5
i need to update t2.c2 = t3.c2
for the cases
when t1.c1 = t2.c1 (t1.c1 will have two rows in t2.c1)
t1 t2 t3
== ============ ===========
c1 c2 c3 c1 c2 c3 c1 c2
-- --------- -------------- --------------
abc1 abc1| xyz1| xyz1 mnp
abc2 abc1| xyz2| xyz4
abc2 abc2| XYz3|
abc2
t1.abc1, t1.abc2, and t1.abc3 is c1 above in table1
t2.abc1, t2.abc1 .... is c1 above in table2
i need to update column2 (t2.c2) of table1 = with value in column 2 in table 3 in case when
t1.c1 = t2.c1 and t2.c3 = t3.c1 (if t1.c1 = t2.c1 but t2.c3 doesnt have value in t3.c1 then
no update) and t1.c3 = "abc' (additional condition).
for above example i would expect MNP appear in t1.c2 (one
t1 t2 t3
== ============ ===========
c1 c2 c3 c1 c2 c3 c1 c2
-- --
abc1 abc abc1| MNP xyz1| xyz1 MNP
abc2 ppp abc1| xyz2| xyz4
abc2 abc2| xyzz3|
abc2
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Update t2
set t2.c2 = t3.c2
from t1, t2, t3
where t1.c1=t2.c1
and t2.c2 = t3.c2
and t1.c4='ABC'
and t1.c5='XYZ'