I have three tables, namely:
Product ProductVariant SizeVariantProduct is the master table , productvariant is its child table of it and sizevariant is productvariant's child table.
All these tables have column of status which indicates whether they are alive or not. I want to check that whether there are any products whose productvariants and sizevariants status is dead but the product itself is alive.
select * from product p where p.status = 'alive' and not exists (select 1 from productvariant where productid = p.id and status='alive')should get you all products that don't have an 'alive' variant. following the same formula, you could also check for product variants without any 'alive' size variants:
select * from productvariant pv where p.status = 'alive' not exists (select 1 from sizevariant where productvariantid = pv.id and status='alive')