?
Solved

copy rows into same table

Posted on 2006-12-01
3
Medium Priority
?
765 Views
Last Modified: 2008-01-09
Hello,

I want to copy some rows into same table with a different value for one column. For example, I have a table with three colums called 'name', 'phone', and 'country' and this table uses auto increment for pk.  Now, I want to copy rows whose country is canada into same table but different country name, japan. Is there any easy way to do that?

Thanks
0
Comment
Question by:joonjoejo
3 Comments
 
LVL 19

Accepted Solution

by:
VoteyDisciple earned 2000 total points
ID: 18055488
INSERT INTO the_table (name, phone, country)
(SELECT name, phone, 'Japan' AS country FROM the_table WHERE country='Canada');
0
 
LVL 32

Expert Comment

by:awking00
ID: 18056412
insert into table select name, phone, replace(country,'Canada','Japan)
from table where country = 'Canada';
0
 
LVL 11

Expert Comment

by:star_trek
ID: 18065362
You don't need to alias as
INSERT INTO the_table (name, phone, country)
(SELECT name, phone, 'Japan' FROM the_table WHERE country='Canada');
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month16 days, 17 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question