Need help on query

Database

Need help on query

Hi All,

I have a table with the following details,say

ref_cd yr_no mh_no column_ind
s100 2006 3 X
s100 null null D
s100 null null T
s101 2006 1 X
s101 2006 null D
s101 2006 null T
s102 2006 4 X
s102 2006 null D
s102 2006 null T
s103 2006 6 X
s103 2006 null D
s103 2006 null T

Now, my query is
What UPDATE statement should I use such that those yr_no and mh_no with column_ind 'D' and 'T' should be same as yr_no and mh_no with column_ind 'X' with respect to its ref_cd
2 REPLIES

Re: Need help on query

update mt
from my_table mt
,(select ref_cd
,yr_no
,mh_no
where column_ind = 'X') dt
set yr_no = dt.yr_no
,mh_no = dt.mh_no
where mt.ref_cd = dt.ref_cd
and mt.column_ind in ('D','T');

Re: Need help on query

Thanks again Barry. Infact I was trying it around

Instead of update table from.... set,
I was trying update table set ..... from...

Thanks for the sol. It helped me.