I have two tables, t1
and t2
with two columns each - id_user
and age
.
How do I update t1.age
to the greatest of t1.age
and t2.age
for matching ID's and leave t1.age
unchanged if there is no matching ID in t2
.
Before update:
t1 +-------+---+ |id_user|age| +-------+---+ | 1| 5| +-------+---+ | 2| 10| +-------+---+ | 3| 10| +-------+---+ t2 +-------+---+ |id_user|age| +-------+---+ | 2| 12| +-------+---+ | 3| 8| +-------+---+ | 4| 20| +-------+---+
After update:
t1 +-------+---+ |id_user|age| +-------+---+ | 1| 5| +-------+---+ | 2| 12| +-------+---+ | 3| 10| +-------+---+