deleting records from a table based on the fields of another table ms sql

I have a table1 with field1 and a table2 with field2

I want to delete all records in table1  that do not have a match in table 2 (if john is in table1 and not in table2 I want it deleted) I have done it in very complicated ways using left joins, temprary tables.. but there must be an easier way
robrodpAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
edlunadConnect With a Mentor Commented:
Try this...

DELETE FROM Table1
WHERE Field1 NOT IN 
    (SELECT Field2 
     FROM Table2)

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.