Solved

INSERT INTO

Posted on 2004-10-13
2
327 Views
Last Modified: 2006-11-17
Hi Experts,

I have two tables A and B

A table has columns A1 A2
B table has              B1 B2

A1 is num from 1 to ~
B1 is num from 1 to ~

Let say I have in table A

1  MICHAEL
2  JOHN
3  JERRY

In table B I have

1 JEAN
2 ROY
3 SAM
4 GERALD

etc

I need to INSERT at the end of table A all rows from table B so that I have this result:

1  MICHAEL
2  JOHN
3  JERRY
4 JEAN
5 ROY
6 SAM
7 GERALD

Thank you.
0
Comment
Question by:fpoyavo
2 Comments
 
LVL 26

Accepted Solution

by:
Hilaire earned 500 total points
ID: 12299836
if the A1 is an auto-incremental identity field then you just need to

insert A(A2) select B2 from B

if it's not an identity field, you can do

insert A(A1, A2) select B1 + A1MAX,  B2
from B
cross join (select max(A1) as A1MAX from A) derived

0
 
LVL 15

Expert Comment

by:jdlambert1
ID: 12299845
INSERT TableA (NameColumn)
SELECT NameColumn
FROM TableB b
WHERE NOT EXISTS (SELECT NameColumn FROM TableA a WHERE a.NameColumn = b.NameColumn)
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

708 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

11 Experts available now in Live!

Get 1:1 Help Now