Link to home
Start Free TrialLog in
Avatar of jgordin
jgordin

asked on

sql update (better version of Q_22755932.html)

sorry for the confusion (https://www.experts-exchange.com/questions/22755932/sql-update.html).
i will try to explain one more time:

table 1 = t1 has columns c1, c2, c3, c4, and c5
table 2 = t2 has columns c1, c2, c3
table 3 = t3 has columns c1, c2

t1.c1 corresponds to t2.c1 that is t1.c1 is populated with ABC1,ABC2,ABC3..etc. while t2.c1 is populated with ABC1, ABC1, ABC2, ABC2, ABC3 , ABC3. there are to rows/entries in t2 for every entry in t1.

column c3 of table2 is populated with XYZ1, XYZ4, XYZ1 ,XYZ5, XYZ1, XYZ10. column c2 of table3 is populated with XZY1,XYZ2,ZYZ3, ... XYZN (all avaialble enetries)

i need to updated table2.c2 with table3.c1 in case when

table1.c4 = 'Val1' and table1.c5 = 'val5'

and table1.c1 = table2.c1
and table2.c3 =table3.c2
ASKER CERTIFIED SOLUTION
Avatar of amit_g
amit_g
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jgordin
jgordin

ASKER

when i run:
select count(*)
from table2 t2
inner join table1 t1 on t1.c1 = t2.c1
where t1.c4 = 'Val4' and t1.c5 = 'val5'

i get the number N which is 2*the number of rows in tabe t1.

If i run

select count(*)
from table2 t2
inner join table1 t1 on t1.c1 = t2.c1
inner join table3 t3 on t2.c2 = t3.c2
where t1.c4 = 'Val4' and t1.c5 = 'val5'

I get the number N >>>>> then number of rows in table1.

I dont think that makes sense I would expect to see the same number of rows as in the first query.

Anyone has any ideas?

Thanks.
There must be more than one item in table 3 for the join condition t2.c2 = t3.c2 and that is why the more rows must be resulting from the join.
Avatar of jgordin

ASKER

i figure that out. thanks.