Update a third column based on comparison of two others?
I have a column of non-unique values that I need to compare to a column of unique values. I then want to update a third column if the value from the non-unique column matched a value in the unique column. ![alt text] : /storage/temp/2622-img-one.png Is there a way to do this in SQl 2008? All of the values are in the same table. I imagine I need to update the status column, but I can't figure out how to do the compare to determine the update. Thanks!
WITH unique AS ( SELECT DISTINCT value=unique_values FROM my_table ) UPDATE mt SET Status = CASE WHEN u.value is null THEN 'No Match' ELSE 'Match' END FROM my_table mt LEFT JOIN unique u ON u.value = mt.[Non-Unique] ;