Reputation: 459
I want to update the blank name column in client table using the non-blank column with same client number. Do you know how I should modify the below SQL? Thanks,
UPDATE CLIENT
SET NAME=(SELECT NAME FROM CLIENT WHERE (NAME IS NOT NULL AND NAME<>'') )
FROM CLIENT C1, CLIENT C2
WHERE (NAME IS NULL OR NAME='') AND C1.CLIENT_NO=C2.CLIENT_NO
Upvotes: 2
Views: 50
Reputation: 1269633
I would recommend using window functions for this purpose:
with toupdate as (
select c.*, max(name) over (partition by client_no) as maxname
from client c
)
update toupdate
set name = maxname
where name is null or name = '';
Upvotes: 1