Let's say I have 2 tables (tb1
, tb2
) with both the following schema:
CREATE TABLE tb1 (
col1 INT NOT NULL,
col2 TEXT NOT NULL,
col3 TEXT NOT NULL,
col4 REAL
);
How do I find records of tb1
which are not present in tb2
on columns col1
, col2
, col3
?
I researched on this, this and this but so far they're all finding records only on one column. I've also used the codes/logic in these links but ended up returning the wrong result with really bad performance (45K records on tb1, 1.7M records on tb2). I'm trying to implement this on SQLite.
If you wanna see, here's my sample code (using left join w/ where is null), but don't rely on it:
SELECT *
FROM tb1
LEFT JOIN tb2
ON
tb1.col1 = tb2.col1 AND
tb1.col2 = tb2.col2 AND
tb1.col3 = tb2.col3
WHERE
tb2.col1 IS NULL AND
tb2.col2 IS NULL AND
tb2.col3 IS NULL