Solved

INSERT INTO

Posted on 2004-10-13
2
367 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 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

690 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