MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Laplink Gold 2008 - $15 Off with Coupon Code CJM9NE
  #1  
Old June 16th, 2002, 11:16 PM
maryer maryer is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 13 maryer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old June 17th, 2002, 03:59 AM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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

Reply With Quote
  #3  
Old June 17th, 2002, 04:11 AM
mytch mytch is offline
Dev Articles Novice (500 - 999 posts)
 
Join Date: Apr 2002
Location: Sydney, Australia
Posts: 589 mytch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
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

Reply With Quote
  #4  
Old June 17th, 2002, 04:31 AM
maryer maryer is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 13 maryer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
+--------------+----------------------------------------------------------------
-----------------------------+------+-----+---------+----------------+
| 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

Reply With Quote
  #5  
Old June 17th, 2002, 02:52 PM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 6
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
Lightbulb

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.

Reply With Quote
  #6  
Old June 18th, 2002, 05:58 AM
maryer maryer is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 13 maryer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thank you very much:-)

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > mysql tables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway