Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mysql tables

Status
Not open for further replies.

maryer

IS-IT--Management
Jun 10, 2002
16
CY
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
 
Do you have a field that the tables can be linked on which is uniquie in both?
***************************************
Party on, dudes!
[cannon]
 
I have two tables for the one same form. one is request part and another is admin part which has to be filled by admin when request part is done. They both have different fields only id number is common for them. So it can be a lot of requests and only by time admin part for those request.id can be filled. i kept 2 separate tables so far but now i need to merge them into one and just UPDATE new_table when i want to fill out admin (new fields) part. For cliarlier explanation i want to put here description of those tables:
request table:
+--------------+-----------------------------------------------------+
| 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('bla','bla')
| YES | | NULL | |
| department | enum('bla','bla','bla','bla','bla','bla') | 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-admin table:
+-----------+--------------+------+-----+---------+-------+
| 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 | |
+-----------+--------------+------+-----+---------+-------+

hope this will give u a key what i want to do
thank you in advance
 
does the id match in both ?

i.e if you have details in tableA with id 1, do the details in table B id 1 belong to its table a partner?

if so, is this true for the whole recordset?

We can then select table A id=1 where table b id=1 to give us related records.

Are you going to make a completely new table or modify one of the existing ones?

Alter your table to add the fields required (or make a new table so that there is no risk of data loss if your query is wrong).

INSERT INTO new_table (field1,field2,field3,etc,etc) SELECT a.field1,a.field2,a.field3,b.field1,b.field2,b.field3) FROM TABLE_A a, TABLE_B b where a.id = b.id;

***************************************
Party on, dudes!
[cannon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top