469,600 Members | 2,326 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,600 developers. It's quick & easy.

How to Copy Table1 to Table2 ?

I have 2 tables in a database:

As an example, let's say Table1 has 20 rows, like this:

Table1:
CategoryNumber CategoryName
1000 Radios
1001 CD Players
.... ...
1019 Older Electronics

Let's say Table 2 has 12 rows, like this
Table2:
Column1 Column2 ProductCategory
0000001 Dan Old TVs
0000002 Steve Old Computers
.... ...
0000011 Debbie Old Guitars

How do I copy all rows of Table1 to Table2 in as few MySQL statements as
possible ?
In otherwords, without writing 20 separate SQL Insert statements ?

Also, the columns from Table1 go into Table2 as described below:
Table1.CategoryNumber ---> Table2.Column1
"Owners Unknown" ---> Table2.Column2
Table1.CategoryName ---> Table2.ProductCategory

Many thanks for your help and patience regarding this newbie question.
Sincerely,
jc

Jul 19 '05 #1
3 2045
Hi,

You can use this format for insert
INSERT INTO tb2(fldID) SELECT tbl.fldOrder_ID FROM tbl WHERE tbl.fldOrder_ID
100;The where clause is optionalJohan

"JC-Atl" <Em***@WithHeld.net> schreef in bericht
news:xD*****************@bignews4.bellsouth.net... I have 2 tables in a database:

As an example, let's say Table1 has 20 rows, like this:

Table1:
CategoryNumber CategoryName
1000 Radios
1001 CD Players
... ...
1019 Older Electronics

Let's say Table 2 has 12 rows, like this
Table2:
Column1 Column2 ProductCategory
0000001 Dan Old TVs
0000002 Steve Old Computers
... ...
0000011 Debbie Old Guitars

How do I copy all rows of Table1 to Table2 in as few MySQL statements as
possible ?
In otherwords, without writing 20 separate SQL Insert statements ?

Also, the columns from Table1 go into Table2 as described below:
Table1.CategoryNumber ---> Table2.Column1
"Owners Unknown" ---> Table2.Column2
Table1.CategoryName ---> Table2.ProductCategory

Many thanks for your help and patience regarding this newbie question.
Sincerely,
jc

Jul 19 '05 #2
Hi,

You can use this format for insert
INSERT INTO tb2(fldID) SELECT tbl.fldOrder_ID FROM tbl WHERE tbl.fldOrder_ID
100;The where clause is optionalJohan

"JC-Atl" <Em***@WithHeld.net> schreef in bericht
news:xD*****************@bignews4.bellsouth.net... I have 2 tables in a database:

As an example, let's say Table1 has 20 rows, like this:

Table1:
CategoryNumber CategoryName
1000 Radios
1001 CD Players
... ...
1019 Older Electronics

Let's say Table 2 has 12 rows, like this
Table2:
Column1 Column2 ProductCategory
0000001 Dan Old TVs
0000002 Steve Old Computers
... ...
0000011 Debbie Old Guitars

How do I copy all rows of Table1 to Table2 in as few MySQL statements as
possible ?
In otherwords, without writing 20 separate SQL Insert statements ?

Also, the columns from Table1 go into Table2 as described below:
Table1.CategoryNumber ---> Table2.Column1
"Owners Unknown" ---> Table2.Column2
Table1.CategoryName ---> Table2.ProductCategory

Many thanks for your help and patience regarding this newbie question.
Sincerely,
jc

Jul 19 '05 #3
Hi,

You can use this format for insert
INSERT INTO tb2(fldID) SELECT tbl.fldOrder_ID FROM tbl WHERE tbl.fldOrder_ID
100;The where clause is optionalJohan

"JC-Atl" <Em***@WithHeld.net> schreef in bericht
news:xD*****************@bignews4.bellsouth.net... I have 2 tables in a database:

As an example, let's say Table1 has 20 rows, like this:

Table1:
CategoryNumber CategoryName
1000 Radios
1001 CD Players
... ...
1019 Older Electronics

Let's say Table 2 has 12 rows, like this
Table2:
Column1 Column2 ProductCategory
0000001 Dan Old TVs
0000002 Steve Old Computers
... ...
0000011 Debbie Old Guitars

How do I copy all rows of Table1 to Table2 in as few MySQL statements as
possible ?
In otherwords, without writing 20 separate SQL Insert statements ?

Also, the columns from Table1 go into Table2 as described below:
Table1.CategoryNumber ---> Table2.Column1
"Owners Unknown" ---> Table2.Column2
Table1.CategoryName ---> Table2.ProductCategory

Many thanks for your help and patience regarding this newbie question.
Sincerely,
jc

Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by JC-Atl | last post: by
2 posts views Thread by ja | last post: by
5 posts views Thread by Peter CCH | last post: by
1 post views Thread by Sean Howard | last post: by
4 posts views Thread by Dejan | last post: by
4 posts views Thread by GTi | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.