superman69 Posted February 18, 2009 Share Posted February 18, 2009 hi i am a beginner at mysql im trying to make a query that determines cousins, nephews,grandparent can somebody help me please in how to do this would appreciate it, this is how my table looks like id firstname lastname gender dateofbirth SpouseID MotherID FatherID Quote Link to comment https://forums.phpfreaks.com/topic/145807-problem-with-query/ Share on other sites More sharing options...
NargsBrood Posted February 20, 2009 Share Posted February 20, 2009 cousins: I dont think MySQL is power enough to do this one but give it a try: select * from [table] where mother_id = ( select id from [same table] where mother_id = (select mother_id from [table] where id = ( select mother_id from [table] where id = [id for person you want cousins of] ))) grandmother: select * from [table] where id = ( select mother_id from [table] where id = ( select mother_id from [table] where id = [id for person you want grandparents of])) newphes: and i dont think MySQL is power enough to do this one either: select * from [table] where mother_id = ( select id from [table] where mother_id = ( select mother_id from [table] where id = select mother_id from [table] where id = [id for person you'd like newphews of])) Quote Link to comment https://forums.phpfreaks.com/topic/145807-problem-with-query/#findComment-767148 Share on other sites More sharing options...
fenway Posted February 23, 2009 Share Posted February 23, 2009 Please read the stickies -- there a link to a dev article of hierarchichal data. Quote Link to comment https://forums.phpfreaks.com/topic/145807-problem-with-query/#findComment-769045 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.