Page 1 of 1

Copy from table to table

Posted: Wed Feb 04, 2004 9:44 am
by mccommunity
I need to build a utility that will copy one table to another and reorder it to go into the correct columns on the second table:

ex: table1.column1 ->goes to table2.column13
table1.column2 -> table2.column9
table1.column3 -> table2.column1

and so on......


Is there a function or a tutorial on a way to do this? I have done a copy table to tablenew but this is not the same. Thanks.



mark

Posted: Wed Feb 04, 2004 12:50 pm
by Weirdan

Code: Select all

mysql> select * from tst1;
+------+------+
| id   | bid  |
+------+------+
|    1 | as   |
|    3 | qa   |
|    6 | lu   |
|    7 | hu   |
|   34 | bra  |
+------+------+
5 rows in set (0.01 sec)

mysql> select * from tst2;
Empty set (0.00 sec)

mysql> insert into tst2 select bid as qud, id as lid from tst1;
Query OK, 5 rows affected (0.03 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> select * from tst2;
+------+------+
| qud  | lid  |
+------+------+
| as   |    1 |
| qa   |    3 |
| lu   |    6 |
| hu   |    7 |
| bra  |   34 |
+------+------+
5 rows in set (0.00 sec)

mysql>
Is that is what you're looking for?

Yes... thank you

Posted: Wed Feb 04, 2004 1:40 pm
by mccommunity
Yes this is it, thanks.