Solved

copy rows into same table

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

696 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