Solved

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

Posted on 2011-09-27
1
204 Views
Last Modified: 2012-05-12
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
Comment
Question by:robrodp
1 Comment
 
LVL 9

Accepted Solution

by:
edlunad earned 500 total points
ID: 36713906
Try this...

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

Open in new window

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now