0

I get daily update files of progress on a project that have no date field. I have added a date column to the first Table and imported the 1st and 2nd tables into SQLIte. Now I want to delete from the 2nd table, data that already exists in the 1st table so that I can add a new date to the 2nd table and then insert the 2nd table into the 1st table. The problem I am having is with the delete from 2nd table part. Column4 data Intersects in both Tables.

I tried the following SQL statement, but it deletes all the rows from Table2:

DELETE from Table2 WHERE exists (SELECT Col4 from Table1 INTERSECT SELECT Col4 from Table2);

Any help is appreciated.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Arveedar
  • 3
  • 1

1 Answers1

1

Exists checks the existence of rows in your subquery. Your problem will be solved by using "not in" statement

DELETE from Table2 WHERE Col4 not in (SELECT Col4 from Table1 INTERSECT SELECT Col4 from Table2);
alexsoff
  • 61
  • 3