|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
mysql tables
Hello there
i have 2 mysql tables. How can i merge them into one without losing any data. Should I make ALTER 1st table and add the same fields the 2nd table has and then how can i transfer all datas from the 2nd to the 1st table. Thank you in advance |
|
#2
|
|||
|
|||
|
can you show me the data structure of the table please? that way we can get a better idea of what your trying to do
|
|
#3
|
|||
|
|||
|
Maryer,
Yes, you could use multiple ALTER TABLE statements to add the fields from the 2nd to the 1st or vice versa and then create a script to update table 1 with table 2's extra fields. How are the 2 tables replated? I would assume that there's a primary key in table 1 that table 2 is related to? As Ben said, please post your table structures (get them using describe table_name; at the mysql promot) and we can go from there ![]() |
|
#4
|
|||
|
|||
|
+--------------+----------------------------------------------------------------
-----------------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------------+---------------------------------------------------------------- -----------------------------+------+-----+---------+----------------+ | id | int(11) | | PRI | NULL | auto_increment | | name | varchar(100) | YES | | NULL | | | organization | varchar(100) | YES | | NULL | | | site | enum('STP','UMCOR') | YES | | NULL | | | department | enum('Admin','Health','Information Management','Noah''s Ark','N utrition','Social Services') | YES | | NULL | | | email | varchar(255) | YES | | NULL | | | reqdate | date | YES | | NULL | | | needdate | date | YES | | NULL | | | url | varchar(255) | YES | | NULL | | | description | text | YES | | NULL | | | timestamp | timestamp(14) | YES | | NULL | | +--------------+---------------------------------------------------------------- and the 2nd table is +-----------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+--------------+------+-----+---------+-------+ | id | int(11) | | PRI | 0 | | | recvdby | varchar(100) | YES | | NULL | | | recvddate | date | YES | | NULL | | | assigned | varchar(100) | YES | | NULL | | | assidate | date | YES | | NULL | | | complby | varchar(100) | YES | | NULL | | | compldate | date | YES | | NULL | | | testby | varchar(100) | YES | | NULL | | | testdate | date | YES | | NULL | | | appliedby | varchar(100) | YES | | NULL | | | appldate | date | YES | | NULL | | | urlaffect | varchar(255) | YES | | NULL | | +-----------+--------------+------+-----+---------+-------+ so these are my tables and table1.id=table2.id thank you in advance for your kind help |
|
#5
|
|||
|
|||
|
This will be pretty simple for you:
You have only 2 steps. 1- Create a new table with all the field names and sized so all possible data can fit 2- Do an Insert With a Select from both tables. e.g : Insert into <new table> (field1,field2...., fieldn) select table1.id, table1.field1... table2.field1, table2.field2... table2.fieldn where table1.id=table2.id Now you can do a select on the new table and see if it matches your original data. |
|
#6
|
|||
|
|||
|
Thank you very much:-)
|
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > mysql tables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|