sql server - Select Parent Record With All Children in SQL -


Assume that I have two tables, there are many children for "parents" and "child" parents : Many relationships are implemented through a standard cross-referencing table.

I want to find all the records of parents who have all the members of a given set of SQL (specifically the MS SQL server T-SQL; 2005 syntax is acceptable).

For example, let's say I have:

  • List item
  • Guardian
  • Child Charlie Alice, Bob
  • Childhood mention
  • My goals are:

    • I have children as Charlie, so I have to include Ellis and Bob as a result
    • If I have children Charlie and David, I want to include results in Alice and No Bob I am
    • If I have hairstyles Charlie, David, and Eve, then I do not want to be included in the results.
    •   SELECT Parent.ParentID, Child (s) from COUNT (*) ChildPaint at INNER ChildPaint. FamilyID = Parents Parents Ener Join Child On Child On Childed = Child .CildID Where & lt; ChildFilterCriteria & gt; Parents by parents Parental Number COUNT (*) = (Select Child (Child. Child ID) Child  

Comments