• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

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
0
robrodp
Asked:
robrodp
1 Solution
 
edlunadCommented:
Try this...

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

Open in new window

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now