I have two tables that are joined together.
A has many B
Normally you would do:
select * from a,b where b.a_id = a.id
To get all of the records from a that has a record in b.
How do I get just the records in a that does not have anything in b?
Select Id_pk, col1, col2...,coln from table1 MINUS Select Id_pk, col1, col2...,coln from table2; You can quickly check how many records are having mismatch between two tables. The only drawback with using UNION and MINUS is that the tables must have the same number of columns and the data types must match.
select * from a where id not in (select a_id from b)
Or like some other people on this thread says:
select a.* from a left outer join b on a.id = b.a_id where b.a_id is null
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With