0

I have a table that has old, legacy data along with new data. The old data does not have all the fields populated like the new data. I want to update the old data so that it matches the new stuff. The fields are ints and represent user IDs. The Created_By field should default to the User_ID -- meaning that in the legacy data, we're setting the created_by value to be the same as the user_id.

Example fields:

Created_By | User_ID
NULL       | 1234
NULL       | 2345
NULL       | 1234
NULL       | 6742
1234       | 1234
2345       | 1234

So I want to only update the NULL values. However, I do not know how to grab the User_ID for each row.

Something like this:

update my_table
set Created_By = ??? (the respective User_ID for that row)
where Created_By is null

So the update should look like this:

Created_By | User_ID
1234       | 1234
2345       | 2345
1234       | 1234
6742       | 6742
1234       | 1234
2345       | 1234

1 Answer 1

8
update my_table
set Created_By = User_ID
where Created_By is null
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.