How can I move data (a row) from table A to table B?

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
Erick020
Forum Newbie
Posts: 22
Joined: Sat Apr 12, 2003 7:11 am

How can I move data (a row) from table A to table B?

Post by Erick020 »

I need to move the displayed informations (echo from a "select querry") to an other table (a similar one - archive).
who can help me ?

Thanks a lot,
Erick.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Erick020
Forum Newbie
Posts: 22
Joined: Sat Apr 12, 2003 7:11 am

Post by Erick020 »

twigletmac wrote:Try INSERT...SELECT:
http://www.mysql.com/doc/en/INSERT_SELECT.html

Mac
Thanks for your answer.
I guess I'm not good enough for that kind of stunt! .... I tried, and I get a "Supplied argument is not a valid MySQL result resource".

Could you please supply a more specific exemple?

I need to move let say: user_id, date1, date2, F1, F2 from table_A to table_B - the data in table_A must be deleted after moving to table_B
and of course the 2 tables structure are similar.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Could you post the code you tried so we can help you debug it?

Mac
Erick020
Forum Newbie
Posts: 22
Joined: Sat Apr 12, 2003 7:11 am

Post by Erick020 »

twigletmac wrote:Could you post the code you tried so we can help you debug it?

Mac
Thanks for you proposition. I guess I get it worked now. I first SELECT*, then INSERT INTO table_B and then DELETE FROM table_A.
It works, even if this not the "right method" to do it !

I still have a small problem... It doesn't want to move the "SPACE" sign. that means, if I have : test tes1, it will move only : test.

Any idea?

Thanks,
Erick.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Again, if you post your code it is a lot easier to help because we don't have to guess at what's going wrong.

Mac
Post Reply