Page 1 of 1

Transfer 1 row from Table A to Table B?

Posted: Fri Feb 14, 2003 4:58 pm
by rxsid
Hi all,

How could I transfer 1 returned row from table A, into table B without getting each column's data in that row (from A) and then doing an insert statement into table B.

Is there a function or sql language to do this?

Thanks

Posted: Sat Feb 15, 2003 11:37 am
by Rob the R
I don't believe there's an automatic way to so this, since it's unusual to have two tables with identical structures that would make it safe to do what you're describing.

You could write a function in PHP that would create an insert statement based on the row data returned from your query. You could then submit this input statement to MySQL. This would avoid having to hard-code each individual column name in your code.

Posted: Mon Feb 17, 2003 7:45 am
by Elena Mitovska
YOu can cope data from one table toanother one with the following statement:

INSERT INTO tableB SELECT * FROM tableA WHERE....

Only make sure that amoutn of columns you select from table A exactly match amount and type of coulmns in table B.

Posted: Mon Feb 17, 2003 11:56 am
by Rob the R
You're right, Elena. I always forget you can do that, probably because I'm always nervous to assume that both tables have matching structures. Thanks for correcting me.