将列移动到另一个表? [英] Move columns to another table ?

查看:91
本文介绍了将列移动到另一个表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





这是我的TableA专栏

Hi,

This is my TableA columns

user_id
active_date <---move this to TableB
name
address
gender





这是我的TableB专栏



This is my TableB columns

num_id
user_id
gen_sub_id





我需要帮助。如何根据 user_id active_date 列移动/复制到TableB?



我尝试了什么:



我正在使用JOIN表及其工作。但我希望active_date移动到TableB



这个我的mysql



I need help. how to move/copy active_date columns to TableB based on user_id?

What I have tried:

i'm using JOIN table and its work. but i want active_date move to TableB

this my mysql

SELECT TableA.user_id, TableA.active_date, TableB.gen_sub_id FROM `TableA` JOIN `TableB` WHERE TableA.user_id = TableB.user_id 

推荐答案

I assume you have rows in your both tables







alter table Table_2 
Add  active_date datetime


UPDATE B    
  SET B.active_date = A.active_date   
from Table_2 B
  INNER JOIN Table_1 A
    ON A.user_id = B.user_id







Lastly, you can drop active_date column from Table_1


这篇关于将列移动到另一个表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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