I have two tables t1, t2 with columns name, invoice, total.
I am using this query to get the rows that in T2 and not in T1
select *
from t2
where name = (select source from info)
except
(select * from t1)
It works fine and returning a couple rows, what I want is to delete these returned rows in one statement.
I've tried this, but it deletes all the rows in T2 not only the returned rows from the query.
delete from t2
where exists ((select *
from t2
where name = (select source from info)
except
(select * from t1)
))
Here is a sample of my data:
T1
T2
THE RETURNED DATA (EXISTS IN T2 AND NOT IN T1 WHERE THE NAME IS C2)
The 3rd table info is get the name which is in this case is C2.
Thanks in advance.



You can do it with a left join of
t2tot1:See the demo.
If you want to use
NOT EXISTS:See the demo.
Results (rows remaining in
t2):