Possible Duplicate:
SQL update query using joins
Table 1 has 2 columns:
-
Has an ID column
-
Has a datetime column
Table 2:
-
Has an ID column
-
Has a datetime column
I need to update the datetime column in table 2 based on the JOIN between table 1 and table 2 on the ID.
Example:
If table1.id = table2.id,
update datetime column on table2
with the datetime column value of table1.
Does this make sense?
How would I go about doing this?
Several options. A correlated subquery ought to work:
This is the easiest method but will be slow for large sets. The other method is this to do the join directly. This requires some slightly vendor-specific syntax:
T-SQL:
MySQL:
(Via: http://blog.ookamikun.com/2008/03/mysql-update-with-join.html)