Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL update from one table to another with condition not working?

Tags:

join

mysql

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!

like image 552
Chris Avatar asked Aug 04 '11 03:08

Chris


People also ask

How do you update a table based on values from another table?

In this article, we will see, how to update from one table to another table based on ID match. We can update the table using UPDATE statement in SQL. The update statement is always followed by the SET command. The SET command is used to specify which columns and values need to be updated in a table.

Why update is not working in MySQL workbench?

You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Editor and reconnect.

Can we use update with WHERE clause?

Notice the WHERE clause in the UPDATE statement. The WHERE clause specifies which record(s) that should be updated. If you omit the WHERE clause, all records in the table will be updated!


1 Answers

Try this syntax out:

UPDATE video_data, video 
SET video_data.date_timestamp = video.date_timestamp
WHERE  video_data.video_id = video.video_id
like image 124
Derek Kromm Avatar answered Oct 27 '22 00:10

Derek Kromm