MySQL select inside select inside select -
what want have parentid numbers children multiple other parents children 1 other parent. rows within same table.
now have far (and works):
select * location parentid in ( select id location parentid in ( select id location parentid = 0 ) ) the thing i'm wondering is, there better/faster way accomplish exact same thing? table consists of 200.000 rows.
if understand correctly, want grandchildren of parentid = 0. personally, think explicit joins easier follow , produce improve execution plan:
select l2.* location l bring together location l1 on l1.parentid = l.parentid bring together location l2 on l2.parentid = l1.id l.parentid = 0; the caveat: perhaps where statement should where l.id = 0. in case can simplify query to:
select l2.* location l1 location l2 on l2.parentid = l1.id l1.parentid = 0; mysql select nested parent children
No comments:
Post a Comment