vincej Posted February 25, 2012 Share Posted February 25, 2012 My table, 'Categories' featured below, has parent categories and child categories. A child category has a parent eg carrots (child) vegetable (parent). I am trying to formulate a query which returns the *name* of the parent category rather than just the parent id and I am failing miserably. Parentid 0 is root category. Many Many Thanks for you help !! id name parentid 18 Poultry 0 19 Beef 0 20 Chicken 18 21 Ribs 19 22 Fish 0 23 Salmon 22 24 Turkey 18 26 Community 0 27 Recent News 26 28 Honey 0 29 Organic Honey 28 30 Steaks 19 31 Scallops 22 Link to comment https://forums.phpfreaks.com/topic/257745-newbie-needs-help-with-formulating-a-query/ Share on other sites More sharing options...
requinix Posted February 25, 2012 Share Posted February 25, 2012 Use a JOIN, like JOIN this table again ON this table's parentid = the joined table's id and include this table again.name as one of the fields you retrieve. Throw in a few aliases while you're at it. Link to comment https://forums.phpfreaks.com/topic/257745-newbie-needs-help-with-formulating-a-query/#findComment-1321050 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.