transfering from one table to another

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
snpo123
Forum Commoner
Posts: 77
Joined: Sat Apr 17, 2004 6:31 pm

transfering from one table to another

Post by snpo123 »

another basic question, but here it goes:

I have two tables. One table I just added to my database and one has been there since the beggining of my site. When people register for my site it creates a row in the first table with a column called user_id that is auto increment. The problem is, I need the table I just added to have the same user ids as the first table. How will I go about doing this besides having to manually update every userid? thanks.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

Code: Select all

UPDATE table2 SET table2.userid=table1.userid WHERE table2.accountid=table1.accoutid
User avatar
snpo123
Forum Commoner
Posts: 77
Joined: Sat Apr 17, 2004 6:31 pm

Post by snpo123 »

magicrobotmonkey wrote:WHERE table2.accountid=table1.accoutid
what exactly does that piece of code do? I tried running only the part before that (as I am trying to update every single user id, not just one) but I got an error saying unknown table, even though I know the table existed. Whats going on?
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

It makes sure that table2's accountid is the same as table1's accountid.
Image Image
Post Reply