Home » RDBMS Server » Server Administration » copying records into an indexed/primary key table
copying records into an indexed/primary key table [message #373756] Fri, 04 May 2001 14:02 Go to next message
Betty Z
Messages: 1
Registered: May 2001
Junior Member
How do I copy/append records from one table into another and have it drop and duplicates. For example, table 1 has 5 records I want to add to table 2, 2 of these records already exist in table 2, how can I add only those 3 records that don't already exist?
Re: copying records into an indexed/primary key table [message #373757 is a reply to message #373756] Fri, 04 May 2001 15:47 Go to previous message
Sundar Venkatasubramaniam
Messages: 26
Registered: May 2001
Junior Member
want to try something like this

assume that source table is s1 with primary key p1 and destination table is d1 with primary key p2,both have same struct and same primary key combination. then

insert into d1 select * from s1 a where not exists(select 1 from d1 where d1.p2 = a.p1)
Previous Topic: Help w/study questions
Next Topic: Long datatype
Goto Forum:
  


Current Time: Tue Jul 02 17:05:17 CDT 2024