Query in MySQL Father and son -
i have table have 3 levels in structure example:
1 son 2 , 2 have son 4 , 6
3 father , son 5
, 1 have other son 7
4 doesn't have son because rule of structure.
well table this:
|id_father| |id_son|
1 2
2 4
3 5
2 6
1 7
only want bringme query every father have 1 son, part of query:
select r.* getname r not exists (select 1 estructura r2 r.id = r2.id_son) , exists (select 1 estructura r2 r.id = r2.id_father , not exists (select 1 estructura r3 r2.id_son = r3.id_father ))
and query :
1 , 3 want 3.
try one:
select id_father estructura group id_father having count(distinct id_son) = 1
Comments
Post a Comment