Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

This is my TableA columns
user_id
active_date <---move this to TableB
name
address
gender


This is my TableB columns
num_id
user_id
gen_sub_id


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 
Posted
Updated 22-Jan-17 0:41am
Comments
Afzaal Ahmad Zeeshan 21-Jan-17 16:14pm    
To move a column permanently to another table requires to either alter that table, or drop the table and rebuild it.

You can try simple one, alter table in MySQL.

1 solution

I assume you have rows in your both tables


SQL
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900