I have a SQL question,I am relatively new to SQL so please don't mind if this too naive.I am working on updating values from one table to another in ORACLE.
Table Person
PersonID BirthPlace
---------------------------
1 Madison,WI,USA
2 Chicago,IL
3 Houston,TX,USA
4 Madison,WI,USA
5 Madison,WI,USA
6 Houston,TX,USA
7 NULL
Table PersonProfile
PersonID CITY STATE COUNTRY
-------------------------------------------------
1 Madison WI USA
2 Chicago IL NULL
3 NULL NULL NULL
4 NULL WI NULL
5 NULL NULL USA
6 HOUSTON NULL NULL
7 NULL NULL NULL
I need to update Table Person Profile with values from Table Person and only need to update the columns in Table Person Profile when they have null values and if both the tables have null value then I need to put 'Unknown'.
I can write separate update statements to update the values in each columns like for updating city :
Update PersonProfile PF
SET PF.CITY= (SELECT
CASE
WHEN PP.CITY LIKE '%MADISON%'
THEN 'MADISON'
WHEN PP.CITY LIKE '% Houston%'
THEN 'HOUSTON'
WHEN PP.CITY LIKE '% CHICAGO%'
THEN 'CHICAGO'
ELSE
'UNKNOWN'
END AS CITY
FROM PERSON PP
WHERE PF.PERSONID=PP.PERSON.ID
AND PF.CITY IS NULL)
and similar queries for updating the state,and country.
What my question is that is there any way I can write a single update statement for updating all three columns instead of updating them one by one? and also instead of using CASE statements if I can use the like operator in a decode function?