I have two tables:
Table1 (ID, Kilometers, Depth)
Table2 (ID, Kilometers, Depth)
Sample Data:
Table 1
1, 0.001, 10
2, 0.002, 11
3, 0.003, 11
Table 2
1, 0.001, 10
2, 0.003, 12
3, 0.004, 15
I need to replace the depth in table 1 with the depth in table 2 according to its Kilometers value.
However, table 2 may not have the value of kilometers for everyone in table 1. Therefore, I need to get the closest value (per kilometer) and use its depth in the replacement.
I was hoping this would be a single SQL statement. Just a direct replacement would be like this:
UPDATE T1, T2 SET T1.Depth = T2.Depth WHERE T1.Kilometers = T2.Kilometers
Anyway, can I adapt this to get the closest value?
source
share