Skip to content
Advertisement

Combine 2 similar update queries into one query

update support set PH1 ='0'||PH1
where PH1 is not null;


update support set PH2 ='0'||PH2
where PH2 is not null;

Is there a way by which I can combine the above two queries (updating the same table) into one single query?

Advertisement

Answer

You may use a case expression to achieve this eg.

UPDATE support
SET
     PH1 = CASE WHEN PH1 IS NOT NULL THEN '0'||PH1  END,
     PH2 = CASE WHEN PH2 IS NOT NULL THEN '0'||PH2  END
WHERE
     PH1 is not null OR PH2 is not null
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement