Updating MySQL from one table to another with a condition does not work?

I tried a solution that seems to work for someone on this issue:

Refresh table a from table b where (conditions) I cannot get it to work, 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 the identifier 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 problem is with my syntax. I'm pretty tired, and maybe it's just my eyes playing with me. Thanks for the help!

+5
source share
3

:

UPDATE video_data, video 
SET video_data.date_timestamp = video.date_timestamp
WHERE  video_data.video_id = video.video_id
+17
UPDATE video_data, video SET video_data.date_timestamp = video.date_timestamp
WHERE video_data.video_id = video.video_id
0

Try the following:

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 simple in that you missed "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 do not think that this is what you want.

0
source

All Articles