Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

INSERT INTO

Posted on 2004-10-13
2
Medium Priority
?
391 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
[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
2 Comments
 
LVL 26

Accepted Solution

by:
Hilaire earned 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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.

647 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