Solved

copy rows into same table

Posted on 2006-12-01
3
761 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
[X]
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
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 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