Connecting Tech Pros Worldwide Forums | Help | Site Map

Insert records

Newbie
 
Join Date: Oct 2007
Posts: 29
#1: Jan 27 '09
I have two tables, the first table has 2000+ records the other only has approx 500....two columns as "linked" that is they are the same information.....PK and date...I would like to insert the remaining 1500+ records into the smaller table.

what I need is an if not exist in table2 insert new record using table1 values PK, date

Any Ideas?

Moderator
 
Join Date: Dec 2006
Location: Europe
Posts: 293
#2: Jan 28 '09

re: Insert records


a- biger table (i is primary key column)
b -smaller table (m is primary key column)

Expand|Select|Wrap|Line Numbers
  1. insert into b select * from a where not exists (select * from b where b.m=a.i);
  2.  
Is it ok?
Newbie
 
Join Date: Oct 2007
Posts: 29
#3: Jan 28 '09

re: Insert records


That was just what I needed, thanks very much!!!!!
Reply