Update records after selecting from group

11 Views Asked by At

I am selecting all records that are duplicates based on any given record (vs simply selecting which field(s) have duplicate records using:

select T1.SN,T1.C,T1.S, T2.cnt
from LS T1
join (
  Select SN,C,S,Count(*) as cnt from LS 
where (C in ('M','B','Q','SI','X') and S='N') group by SN having count(*)>1
) as T2 on T1.SN=T2.SN and (T1.C in ('M','B','Q','SI','X') and T1.S='N') 

I would like to update FieldY to '1' for these selected record.

1

There are 1 best solutions below

0
On

I tried this and it seemed to work, not sure if it is ideal:

Update LS as U1
Inner Join (
select T1.ID,T1.SN,T1.C,T1.S, T2.cnt
from LS T1
join (
  Select SN,C,S,Count(*) as cnt from LS 
where (C in ('M','B','Q','SI','X') and S='N') group by SN having count(*)>1
) as T2 on T1.SN=T2.SN and (T1.C in ('M','B','Q','SI','X') and T1.S='N')) as U2 
On U1.ID=U2.ID set FieldY='1'