开发者

Copy column from table to another in MySQL

开发者 https://www.devze.com 2023-04-04 18:14 出处:网络
I\'m trying to copy a column with data from a table to another in MySQL. But I can\'t wrap my head around it. Both tables have an id column called \'nid\' which fits perfectly.

I'm trying to copy a column with data from a table to another in MySQL. But I can't wrap my head around it. Both tables have an id column called 'nid' which fits perfectly.

I want to move the column called 'field_pref_position_value' from the table 'content_field_pref_position' to the column 'pref_position' in the table 'co开发者_开发技巧ntent_type_player'. I already made the column 'pref_position'.

Any help much appreciated.

EDIT: I made a huge mistake. I copied the column to the table 'content_type_player' instead of 'content_type_transfer' which it should have been, but now when i'm trying to use the same query for content_type_transfer it just returns '0 row(s) affected. ( Query took 0.0015 sec )' without updating the column. Can't figure out what the deal is?

I'm using this Query:

UPDATE content_type_transfer 
JOIN content_field_pref_position 
    ON content_field_pref_position.nid = content_type_transfer.nid 
SET content_type_transfer.pref_position 
    = content_field_pref_position.field_pref_position_value


I think you have just named the same table twice:

UPDATE 
 content_type_player 
SET 
 content_type_player.pref_position = content_field_pref_position.field_pref_position_value 
FROM 
 content_field_**player**
JOIN 
 content_field_pref_position ON content_type_player.nid = content_field_pref_position.nid 


As suggested by @heximal

UPDATE
 content_type_player
SET
  b.pref_position = a.field_pref_position_value
FROM
 content_field_pref_position a
 content_type_player b 
WHERE
 a.nid = b.nid


As suggested by Nielsiano

UPDATE content_type_player JOIN content_field_pref_position ON content_field_pref_position.nid = content_type_player.nid SET content_type_player.pref_position = content_field_pref_position.field_pref_position_value
0

精彩评论

暂无评论...
验证码 换一张
取 消