mysql - Find parent with child -
i have 2 tables
parent{ parent_id } child{ child_id parent_id }
i need find parent parameters children id
ex: find parent has children (1, 2, 3)
i tried "where child_id in (1, 2, 3)" return incorrect parent in case parent has children(1, 2, 3, 4)
i can hard code php ask mysql solution.
maybe add count() condition, if parent has (1,2,3) children , 3 children it's !
select * parent natural join child child.child_id in (1, 2, 3) group parent.parent_id having count(child.child_id) = 3
(not tested)
Comments
Post a Comment