Reputation: 880
in vb.net how would you loop through database1 to check that all records in database2 exist in Database1 and the other way areound if a record exist in database1 and doesnt exist in database2 then delete it from database1. so database2 is my reference
how can i do this using queries, also does it have to include nested looping?
note that the records are not in the same order
Thanks
Upvotes: 1
Views: 873
Reputation: 56755
This query will return all of the rows in the attached table that are not in the local version of the table
SELECT * FROM attachedTable
WHERE col1 NOT IN( SELECT lt.col1 FROM localTable as lt)
And this will do the converse, returning all rows in the local table that are not matched in the remote table.
SELECT * FROM localTable
WHERE col1 NOT IN( SELECT rt.col1 FROM attachedTable As rt)
Upvotes: 1