0

私は2つのテーブルを持っています。table1がtable2と等しいMODELときに、table2を更新したい。ITEMITEM

何か案は?

4

3 に答える 3

2

If I understand correctly, you just want to perform an UPDATE on table2 based on, presumably, foreign keys?

If that's right, this should work:

UPDATE
    table2
    JOIN table1
        ON table1.ITEM = table2.ITEM
SET
    MODEL = 'new value';

The table declaration in an UPDATE statement is the same as is specified in a SELECT statement - so you can use any type of JOIN that fits your table/data.
Docs for UPDATE, SELECT.

于 2012-08-15T16:43:27.320 に答える
2

MySQLでは、次のようにします

UPDATE table1 t1 
           INNER JOIN table2 t2 
                ON t1.id = t2.id
SET t1.col1 = t2.col1, 
    t1.col2 = t2.col2 
于 2012-08-15T16:45:04.633 に答える
0

If you could add an actual query attempt, or something, that might be helpful. Can you try something like the following:

UPDATE table2 JOIN table1 ON table2.ITEM = table1.ITEM SET MODEL = ?
于 2012-08-15T16:43:16.137 に答える