Chris
Chris

Reputation: 764

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 tired and maybe it is just my eyes playing with me. Thanks for the help!

Upvotes: 5

Views: 9762

Answers (3)

Sabeen Malik
Sabeen Malik

Reputation: 10880

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.

Upvotes: 0

ace
ace

Reputation: 7593

UPDATE video_data, video SET video_data.date_timestamp = video.date_timestamp
WHERE video_data.video_id = video.video_id

Upvotes: 0

Derek
Derek

Reputation: 23298

Try this syntax out:

UPDATE video_data, video 
SET video_data.date_timestamp = video.date_timestamp
WHERE  video_data.video_id = video.video_id

Upvotes: 18

Related Questions