2

I am trying to delete some data from one table using multiple table. The problem i am having with this query is that it is deleting data that is not suppose to delete. I want to delete only the Data where ID's in both tables are DIFFERENT. In other words, i want to keep when the ID's in both tables are the same. Here is my query:

delete  Tabel1
from Table1 r join
Table2 w on r.ID <> w.ID
and w.Date_Assigned is not null

1 Answer 1

3

You probably want to do:

delete Tabel1 where Id not in (select Id from Table2)

Your statement will probably delete all records from Tabel1, because for every record it will find at least one in Tabel2 with a different ID.

To test this, just run

select r.ID
from Table1 r join
Table2 w on r.ID <> w.ID
and w.Date_Assigned is not null

and you'll understand what the problem is.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.