I currently have a query that returns parent data for parent records that have a subset of child table entries equal to specific values. However, I want to narrow it down to only return parent records that have certain values, but where they are the only child records that belong to this parent, or if the number of child records does not exceed a given value.
Here is an example of a query that only gets me halfway to where I need it:
SELECT parent.item1, parent.item2, parent.index FROM parent INNER JOIN child on parent.index = child.index WHERE child.value IN (11111111, 33333333) GROUP BY parent.item1, parent.item2, parent.index HAVING COUNT(child.value) = 2
Unfortunately, this query returns ANY parent data that has a subset of the identified values ββincluded in the "IN" statement. I only need parent data for parent records whose full child records do not exceed a certain number (or, in my case, do not exceed the number of values ββin the "IN" statement. Is there an easy way to accomplish this
sql mysql sql-server
Don
source share