MySQL update from one table to another with condition not working?
I have tried a solution that seems to work for someone else on this question:
Update table a from table b where (conditions) I can not seem to get it working, MySql gives me a syntax error.
I have two tables, and I need to update a column in one table to the value of another column where an id matches in both tables.
UPDATE video_data SET video_data.date_timestamp = video.date_timestamp FROM video_data JOIN video ON video_data.video_id = video.video_id
I am not sure what the issue is with my syntax. I am quite t开发者_如何学运维ired and maybe it is just my eyes playing with me. Thanks for the help!
Try this syntax out:
UPDATE video_data, video
SET video_data.date_timestamp = video.date_timestamp
WHERE video_data.video_id = video.video_id
UPDATE video_data, video SET video_data.date_timestamp = video.date_timestamp
WHERE video_data.video_id = video.video_id
Try this:
UPDATE video_data SET date_timestamp = (SELECT video.date_timestamp FROM video WHERE video.video_id = video_data.video_id)
Although the error in your actual query is simply that you missed a "SELECT"
UPDATE video_data SET video_data.date_timestamp = SELECT video.date_timestamp FROM video_data JOIN video ON video_data.video_id = video.video_id
But I don't think it is what you want it to be.
精彩评论