SQL:将列数据移动到同一关系中的其他表 [英] SQL: Move column data to other table in same relation
问题描述
我想知道是否有可能将所有数据从表中的一列移到另一张表中. 这就是我想要做的:
I'm wondering if it's possible to move all data from one column in table to another table. Here's what i'm trying to do:
表1:用户-尝试读取+移动的列= oauth_access_key和oauth_access_secret
Table 1 : users - columns trying to read+move = oauth_access_key and oauth_access_secret
表2:account_users-目标列:oauth_token_key,oauth_token_secret
Table 2 : account_users - target columns: oauth_token_key, oauth_token_secret
这些表之间的关系键是"user_id".
The relation key between these tables is "user_id".
在一个查询中有可能吗?我知道这很容易在PHP中完成,但是我想知道是否可以在普通SQL中完成.
Is this possible in one query? I know this is easily done in PHP, but i'm wondering if this can be done in plain SQL.
提前谢谢.
推荐答案
UPDATE users, account_users
SET account_users.oauth_token_key=users.oauth_access_key,
account_users.oauth_token_secret = users.oauth_access_secret
WHERE account_users.user_id=users.user_id;
您可以在 MySQL更新上使用JOIN
语法
这篇关于SQL:将列数据移动到同一关系中的其他表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!