Thursday, 12 September 2013

SQL - update column based on similar column

SQL - update column based on similar column

Were using sql 2008, a sample of the table. I am trying to cleanup(then
will delete duplicates later) where the prev_date field is different when
item# is the same. I want to update both records with the max(prev_date).
Im having a hard time figuring out how to do this for multiple records
with a single statement
key item(int) prev_date(int)
--------------------------------------------------------------------
15086 1163 20121023
16289 1163 20130121
15087 1164 20121024
16290 1164 20130120
15088 1165 20121029
16291 1165 20130120

No comments:

Post a Comment