By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE info (source VARCHAR(100));
INSERT INTO info (source) VALUES ('C2');
CREATE TABLE t1 (name VARCHAR(100), invoice INTEGER, total INTEGER);
INSERT INTO t1 (name,invoice,total) VALUES
('C1',1,150),
('C1',2,300),
('C2',1,200),
('C2',2,165);
CREATE TABLE t2 (name VARCHAR(100), invoice INTEGER, total INTEGER);
INSERT INTO t2 (name,invoice,total) VALUES
('C1',1,150),
('C1',2,300),
('C2',1,200),
('C2',2,165),
('C2',1,220),
('C2',2,170);
11 rows affected
select *
from t2
where name = (select source from info)
except
select * from t1
name | invoice | total |
---|---|---|
C2 | 1 | 220 |
C2 | 2 | 170 |
delete t
from (
select * from t2
where name = (select source from info)
) t
where not exists (
select 1 from t1
where name = t.name and invoice = t.invoice and total = t.total
)
2 rows affected
select * from t2
name | invoice | total |
---|---|---|
C1 | 1 | 150 |
C1 | 2 | 300 |
C2 | 1 | 200 |
C2 | 2 | 165 |