There are two tables
TableA
filedata_id | user_id | filename
1 | 1 | file.txt
2 | 1 | file2.txt
TableB
a_id | date | filedataid | counter | state | cat_id | subcat_id | med_id
99 | 1242144 | 1 | 2 | v | 55 | 56 | 90
100 | 1231232 | 2 | 3 | i | 44 | 55 | 110
I want to move columns cat_id, subcat_id, med_id to TableA where tableA.filedata_id = TableB.filedataid
edit: The result should be a schema change in tableA so it looks like the following and also have the data from those columns in tableB:
TableA
filedata_id | user_id | filename | cat_id | subcat_id | med_id
1 | 1 | file.txt | 55 | 56 | 90
2 | 1 | file2.txt | 44 | 55 | 110
and so on.
Is there a way to do this easily?
You can use
INNER JOINfor that:See this SQLFiddle
UPDATE:
You can change the schema of
TableAlike this:And update new columns of
TableAfromTableBlike this:See this SQLFiddle
For more see MySQL: ALTER TABLE Syntax and MySQL: UPDATE Syntax.