MYSQL query creation
Trying to create a mysql query that will do the following:
For each record within Table 1, find a matching record in Table 2 where column A & B of Table 1 match column Y & Z of Table 2.
Once a match is found, grab column X value from Table 2 record and insert that value into c开发者_如何学Goolumn C of the original record in Table 1.
I hope that makes sense.
How the heck do I do that?
Use a multi-table update, just without modifying any columns from Table 2, as follows:
UPDATE Table1 T1, Table2 T2
SET T1.C = T2.X
WHERE T1.A = T2.Y AND T1.B = T2.Z;
UPDATE table1 INNER JOIN table2 ON table1.a = table2.y AND table1.b = table2.z SET table1.c = table2.x;
精彩评论