How to get where relation has no rows
The
masterProducts
table has a one to many relationship with unitCosts
(one master product has many unit costs). How do I modify whereFilter
if I want to only fetch masterProducts
rows that have no associated unitCosts
?4 Replies
bump
You'd need a subquery that returns a list of masterProducts.id from the unitCosts filter
And the where would be any masterProducts.id not in that "array"
that's what i figured but isn't that terribly inefficient to fetch every single row for the sub query? does this mean a schema update is probably warranted
It is my understanding that in later versions, pg query planner is smart enough to detect subqueries that are not correlated and run them once.
If you weren't using RQB, you could use CTEs to make sure it is actually running once
In any case, nothing that some benchmarks or performace tests wouldn't give you an answer
Or even wherever PG's explain analyze equivalent is from mysql