SQL:将列数据移动到同一关系中的其他表 [英] SQL: Move column data to other table in same relation

查看:106
本文介绍了SQL:将列数据移动到同一关系中的其他表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能将所有数据从表中的一列移到另一张表中. 这就是我想要做的:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆