Reputation: 270
I have been trying to update 1 table based on a value in another table (and there are corresponding Identifers). I simply cannot work out what the syntax is for this, and believe I may have a mix of MS-SQL and MySQL, though very new to this type of coding so having issues unravelling this one.
I am trying to get this query working in MySQL
UPDATE timetable As T
SET T.TrainsArrived = T.TrainsArrived + A.TrainsToday
INNER JOIN
(
SELECT TrainID, TrainsToday
FROM TrainTracker
) A ON A.TrainID = T.TrainID;
The issue that the MySQL console is telling me about is on the word 'INNER' and that it is expecting EOF or ';'
Any assistance would be greatly appreciated!
Upvotes: 0
Views: 28
Reputation: 521249
Use the following syntax, and note that the subquery doesn't seem to even be necessary here:
UPDATE timetable AS T
INNER JOIN TrainTracker AS TT
ON TT.TrainID = T.TrainID
SET TrainsArrived = T.TrainsArrived + TT.TrainsToday;
Upvotes: 1