Reputation: 2565
Table structure:
| id | parent |
1 0
2 1
3 1
4 2
5 2
6 2
How can I get the id of the parent row that have more than 2 childs ? (in the above case should return only the id=2 row)
Upvotes: 0
Views: 2192
Reputation: 93734
I believe this is enough to find the parent id
SELECT parent
FROM tablename
GROUP BY parent
HAVING Count(parent) > 2
Upvotes: 1
Reputation: 4844
Try this query
SELECT *
FROM tablename
WHERE id IN
(
SELECT parent
FROM tablename
GROUP BY parent
HAVING COUNT(parent) > 2
)
Upvotes: 2