Link to home
Start Free TrialLog in
Avatar of AkAlan
AkAlan

asked on

How to return only those rows in a related table where there are more than one related row

I have two tables that are related. I would like to write a query that returns only those rows that have more than one related record in the child table.

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you can try something like this...

SELECT     a.field1, COUNT(*) AS Cnt
FROM         ParentTable AS a INNER JOIN
                      ChildTable AS b ON a.field1 = b.field1
GROUP BY a.field1
HAVING      (COUNT(*) > 1)

Open in new window