question

gmoney avatar image
gmoney asked

Hi I'm trying to update a column with MIN(Date) based on distinct IDs. When I execute it updates all columns to same MIN(Date). I need it to add the different MIN(Date)s based on the unique IDs. Thanks in advance

update #Sample_2019 set Date_Of_Service = a.DOS

from ( Select Unique_ID, MIN(DOS) as DOS

From #Sample_2019 a

inner join [dbo].[MainTable] b on Unique_ID1 = b.Unique_ID

group by Unique_ID

) a

updatedatefunction
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jon Crawford avatar image
Jon Crawford answered

update #Sample_2019 set Date_Of_Service = a.DOS

from #Sample_2019 targetTable

JOIN ( Select Unique_ID, MIN(DOS) as DOS

From #Sample_2019 a

inner join [dbo].[MainTable] b on Unique_ID1 = b.Unique_ID

group by Unique_ID

) a ON targetable.Unique_ID = a.Unique_ID

10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

gmoney avatar image
gmoney answered

It worked! thanks!

10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.