mysql - My query returns a lot of columns -
let's have kind of structure in database:
table grandparent (id, name) table parent (id, grandparentid, name) table child (id, parentid, name)
this not real structure, theory... (considering fact structure can replaced 1 person table parentid in it, yes know). , of course let's suppose there no genders... ancestor , descendant, that's it.
okay. so. let's these tables classified age. old people go grandparent table. middle age people go parent table, children go children table.
so how can query children belonging 1 grandparent?
i tried this:
select * child join parent on child.parentid = parent.id join grandparent on parent.id = grandparent.grandparentid grandparent.greatgrandparentid = 1;
actually works, returns lot of columns (not rows, columns). little annoying can live that. i'd glad improvements. thank you.
you want columns child
table, rather columns across tables in query. luckily, straightforward achieve. use child.*
instead of *
, resulting in:
select child.* child join parent on child.parentid = parent.id join grandparent on parent.id = grandparent.greatgrandparentid grandparent.greatgrandparentid = 1;
Comments
Post a Comment