transfer sql "table1" to "table2"

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
stevengoh
Forum Newbie
Posts: 5
Joined: Tue Nov 06, 2007 3:23 pm

transfer sql "table1" to "table2"

Post by stevengoh »

hi

Can I check with all of you how to transfer sql "table1" pid row number 2 to "table2" pid highest row. Like say my "table2" highest row currently at pid 11, so it will transfer to number 12.

thank
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: transfer sql "table1" to "table2"

Post by panic! »

try the databases forum.
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Re: transfer sql "table1" to "table2"

Post by Rovas »

Use mysql_insert_id to retrieve the last id. Be careful it only works good in no race environment (i.e. multiple users updating the same tables) and must one auto increment column.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: transfer sql "table1" to "table2"

Post by pickle »

Moved to Databases.

mysql_insert_id() works fine in race conditions, because that function returns the last inserted ID [em]for your connection[/em] not for the table. If you've got 20 people updating the table & the all call mysql_insert_id(), they'll all get 20 different numbers.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
stevengoh
Forum Newbie
Posts: 5
Joined: Tue Nov 06, 2007 3:23 pm

Re: transfer sql "table1" to "table2"

Post by stevengoh »

thank

but I think that is not the solution bec I just want to transfer one row from table1 to table2 in mysql . Use something like trigger is it??

pls help
Post Reply