Skip to content
Advertisement

Update table value from a second table by joining a third table

I have 3 tables, TableA, TableB and TableC

I want to migrate the data from TableA column DateA to TableB column DateB, only if the date field is null in table B (I don’t want to overwrite any existing data)

I need to join TableA and TableB using TableC to match the A and B rows that should be updated by their RobotNumber.

TableA

TableB

TableC

I have tried to join the tables and do the update like so but the query times out:

Advertisement

Answer

I would start by getting rid of the NOT IN:

Then, you should also have indexes on TableC(RobotID) and TableA(RobotNumber, DateA).

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement