Using PostgreSQL, I want to update a column. The information how to update is in another table.
My try was this, but it also updates rows I don't want to update:
update table_1
set column_x = (
select table_2.rename
from table_2
where table_2.rename IS NOT NULL
and table_1.id = table_2.id)
How to modify the query?
Maybe this helps to explain my problem: http://www.sqlfiddle.com/#!15/318fb/1
t2
fortable_2
but still reference the original name which is not possible - the mismatch betweentable2
andtable_2
aside. And your test needs to consider actual NULL values. I added an extended test case to my answer. – Erwin Brandstetter Apr 6 '16 at 18:25