Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Inserting records into a table

Author  Topic 

DLProgrammerLisa
Starting Member

1 Post

Posted - 2014-11-07 : 03:29:05
Hi

I am comparing names of people from a table without id field to a table that has those people along with their ids.

I have a select statements using different field combinations that fetches ids of these people and presents the result set like:
table1id,table1firstname,table2firstname,table1lastname,table2lastname

for eg:
1 john john smith smith
1 john j smith smith
1 john jon smith smit

I want to be able to insert all the records from the result set into another table, like in the eg, but only excluding those ones that match all the above fields. How would I do this...Thank you

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-11-07 : 08:45:42
insert into anothertable a
select from originaltable o
where not exists (
select ...your current selectlist ...
from originaltable o1
where o.id = o1.id
)
Go to Top of Page
   

- Advertisement -