Link to home
Create AccountLog in
Avatar of 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.

Avatar of kaufmed
Flag of United States of America image

Link to home
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
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