If I have the following table
| name | nationality |
|---|---|
| AAA | french |
| BBB | english |
| CCC | spanish |
| DDD | dutch |
| BBB | NULL |
| AAA | NULL |
How do I update the NULL values with 'english' and 'french' respectively
I tried the following but it doesn't work:
UPDATE
t1
SET
t1.nationality = known.Nationality
FROM
t1
LEFT JOIN (
SELECT name, max(nationality) FROM t1
) AS known
ON t1.name = known.name
Edit
In the end there are more cases of NULL values for other names
Thanks in advance
SELECT name, max(nationality) FROM t1?UPDATE t1 SET nationality = CASE name WHEN 'BBB' THEN 'english' WHEN 'AAA' THEN 'french' ELSE nationality END WHERE t1.nationality IS NULL AND name IN ( 'AAA', 'BBB' )?