I have following query
select *
from object
where parent_id = ?
and id not in ( select parent_id
from object
where discriminator='ABC')
I have tried to use Joins as follows
select *
from object parent
inner join object child
on (parent.id != child.parent_id)
where child.discriminator='ABC'
But I am getting incorrect result. Is there any way to improve the performance of query in postgres.
Sorry, I guess, I failed to explain my problem in first time,
Below is modified query
select *
from object parent
where parent.parent_id = ?
and parent.discriminator ='XYZ'
and parent.id not in ( select child.parent_id
from object child
where child.discriminator='ABC')
So besically i have been given an id and need to find all it's child, who don't have any child.