How to select all records in the table t2
which t2.t1_id
has no coincidence with t1.id
.
SELECT * FROM t2 LEFT JOIN t1 ON t1.id <> t2.t1_id
Any tips, link or code example would be useful.
How to select all records in the table t2
which t2.t1_id
has no coincidence with t1.id
.
SELECT * FROM t2 LEFT JOIN t1 ON t1.id <> t2.t1_id
Any tips, link or code example would be useful.
If what you want is all t2 records without a matching id in t1, but no columns from t1, you could do:
Select * from t2
WHERE t2.t1_id NOT IN(Select id from T1)
This selects all records in t2, but then filters out those that exist in t1 based on t1_id
You can use a not in
:
SELECT *
FROM t2
WHERE t2.t1_id not in (select id from t1)
Just want to add, NOT EXIST
is better in most cases:
SELECT *
FROM t2
WHERE NOT EXIST (SELECT 1 FROM t1
WHERE t2.t1_id = t1.id)
Otherwise, you can use NOT IN
or LEFT JOIN with NULL