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.
| Author |
Topic |
|
maevr
Posting Yak Master
169 Posts |
Posted - 2009-12-15 : 09:50:29
|
| I have three tables that I want to use to insert data into a new table (newTable).table1 contains all data. table2 and table3 contains data that shall be removed from insert.table1fnr (unique)id1 (unique together with id2)id2 (unique together with id1)col1col2table2 contains data that shall be removed from insertfnr (pk)col1col2table3 contains data that shall be removed from insertid1 (unique together with id2)id2 (unique together with id1)col1INSERT INTO newTable(id1,id2,col1,col2)(select id1,id2,col1,col2from table1where fnr not in (select fnr from table2)and --Dont know how to write the following!table1.id1, table1.id2 not in (select table3.id1, table3.id2 from table3) |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-12-15 : 10:02:47
|
| [code]select id1,id2,col1,col2from table1 aleft join table2 b on a.fnr = b.fnrleft join table3 c on a.id1 = c.id1 and a.id2 = c.id2where b.fnr is null and c.id1 is null and c.id2 is null[/code] |
 |
|
|
|
|
|