Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

copy rows into same table

Posted on 2006-12-01
3
760 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 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

828 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