Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add one table records from one table to another

Status
Not open for further replies.

evergreean43

Technical User
May 25, 2006
165
US
I have a table (called first) where I would like to take another table (called second) and add all of the records to table first.

My attempt doesnt work:
Code:
copy from table second to table first;


Here is an example of what I want to do:
table first
Code:
id    name
1     Jones
2     Richards
3     Carson

table second
Code:
id    name
4     Baker
5     Johnson
6     Hart
7     Barnes

table first after adding table second records
Code:
id    name
1     Jones
2     Richards
3     Carson
4     Baker
5     Johnson
6     Hart
7     Barnes
 
Hi,

You can achieve by executing this

insert into table1
select * from table2;

Regards,
Gunjan
 
The "copy" command isn't really part of SQL. It's an feature in SQL*Plus which allows you to copy data between different databases. It's not really suitable if all the tables are on the same database.
 
You can't use a simple "select * into..." if you want to use a new sequence number for the id#. Use the following

insert into table1
select my_seq.nextval,name
from table2;

This is assuming that you are using a sequence for the insert into table1.

Bill
Oracle DBA/Developer
New York State, USA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top