Page 1 of 1

transfering from one table to another

Posted: Tue Jun 29, 2004 1:36 pm
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.

Posted: Tue Jun 29, 2004 1:57 pm
by magicrobotmonkey

Code: Select all

UPDATE table2 SET table2.userid=table1.userid WHERE table2.accountid=table1.accoutid

Posted: Tue Jun 29, 2004 2:35 pm
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?

Posted: Tue Jun 29, 2004 3:24 pm
by phice
It makes sure that table2's accountid is the same as table1's accountid.