Jump to content

Recommended Posts

I need to copy data and want to make sure I do it correctly.  To make it easy to understand what I am trying to do, I have 2 tables.  Table1 has 2 fields -  ID and Name.  Table2 has 4 fields - ID, First, Middle, Last.  What I want to do is copy the data from the Name field on table1 and put it in the First field on table2.  The same ID numbers are in both tables right now.  When I look at the two tables I see as example this:

 

Table1

ID  Name

2    John

4    Mary

5    Joe 

 

Table2

ID  First  Middle Last

1                        Jones

2                        Smith

3                        Jackson

4                        Gold

5                        Ray

 

What I don't want is to end up with  ID1 being John Jones ID2 being Mary Smith and ID3 being Joe Jackson.  In other words, since the id's order is different in the two tables, I want to make sure they are matched so I end up with ID1 still is just Jones, ID2 is John Smith, ID3 is just Jackson, ID4 is Mary Gold, and ID5 is Joe Ray.

 

Thanks for the help in advance,

Doc

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/221932-need-help-with-copying-data/
Share on other sites

UPDATE Table2
SET First = (SELECT Name FROM Table1 WHERE Table1.ID = Table2.ID LIMIT 1)
WHERE ID IN (SELECT ID FROM Table1)

I'm pretty sure you could do a JOIN (like you would with a SELECT) but I've been using too much MS SQL lately to remember.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.