Solved

copy rows into same table

Posted on 2006-12-01
3
756 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 500 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 31

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now