1

I have the table with two columns companyName and accountName.I want to check the the company value is empty and update the field with value accountName in the same row

testTable
id companyName accountName
1   a            a1
2                b1         //update with b1 in companyNAme field
3   c            c1
4                d1        //update with  d1 in companyNAme field

I want to check if the companyName field is empty then update with companyName with accountName field value .From the abobe example I want to update id 2 companyName name with value b1 and id 4 companyName name with value d1 in postgres.

1 Answer 1

4

It's just a simple update:

UPDATE "testTable" 
SET "companyName" = "accountName"
WHERE "companyName" IS NULL;

It would be better to not have capitalization in the column and table names, to avoid requiring those quotation marks.

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.