If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Copy from table1 to table 2 while matching IDs

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-07-08, 16:26
compsci compsci is offline
Registered User
 
Join Date: Jun 2007
Location: London
Posts: 117
Copy from table1 to table 2 while matching IDs

Hello all,

I have two tables. I have simplified it to:

table1: ID, fromEmail
table2: ID, fromEmail (blank Column)

The ID's of table1 and table2 match, there may be repeated in table2. I want the email fields copied to table2 that have the same ID as table1. I have this so far.
Code:
INSERT INTO table2.fromEmail WHERE table2.ID=table2.ID
Of course that won't do it but I don't know how to get the data from table1. Do I use a select statament? I am so thick

Thank you for any help and direction
Reply With Quote
  #2 (permalink)  
Old 11-07-08, 19:31
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
try this --
Code:
UPDATE table1
INNER
  JOIN table2
    ON table2.ID = table1.ID
   SET table2.fromEmail = table1.fromEmail
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 11-08-08, 12:34
compsci compsci is offline
Registered User
 
Join Date: Jun 2007
Location: London
Posts: 117
Aaah that did it! Thank you! You are a blessing to many forums. I've repped you on another forum for this
Reply With Quote
  #4 (permalink)  
Old 11-10-08, 05:11
ankur02018 ankur02018 is offline
Registered User
 
Join Date: Jun 2007
Posts: 189
Smile

Quote:
Originally Posted by r937
try this --
Code:
UPDATE table1
INNER
  JOIN table2
    ON table2.ID = table1.ID
   SET table2.fromEmail = table1.fromEmail
or

UPDATE table1,table2 SET table2.fromEmail=table1.fromEmail where table2.ID = table1.ID;
Reply With Quote
  #5 (permalink)  
Old 11-10-08, 06:22
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
yeah, but ankur, you're still using an inner join, only using the older, deprecated style instead of the newer, recommended JOIN syntax
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On