Reputation: 7175
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.
Upvotes: 1
Views: 1224
Reputation: 6723
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.
Upvotes: 4