Hello all, I'm having a little trouble with an SQL query. My script consists of the following: Parent/child categories (Top level categories have column 'parent' = 0). Data items held within child categories In the data table I have the columns 'topparent' (the top level category) and 'childparent' (the child category it is in). In the categories table there is the column 'string' which I need to extract. The idea is to list all data items - From this query I need to be able to use the 'string' of the 'topparent' category and the string of the 'childparent' category. So far I've only been able to output just one of the 'string' values and cannot quite figure out how to get both of them. Any help would be much apperciated. Thanks
I assume you have a table [category_id_parent, category_id_child, other_data] and want category->string for both ids ? $sql = ("SELECT a.data, c1.string, c2.string FROM datatable AS a JOIN categories AS c1 ON a.topparent = c1.categoryid JOIN categories AS c2 ON a.childparent = c2.categoryid"; something like that ?
By using that method I have the following. SELECT tutorial.ID, tutorial.type, tutorial.string, tutorial.name, tutorial.description, tutorial.url, tutorial.parent, tutorial.date_added, tutorial.avatar, C1.string, C2.string, user.username FROM tutorial, user JOIN tutorial_cat AS C1 ON tutorial.topparent = C1.ID JOIN tutorial_cat AS C2 ON tutorial.parent = C2.ID WHERE tutorial.active = 1 && user.ID = tutorial.authorID ORDER BY tutorial.date_added DESC Code (markup): The error Im getting is 'Cant execute query Unknown column 'tutorial.topparent' in 'on clause''. The table tutorial does have a column called 'topparent'. Just to clarify: 'topparent' = top level category 'parent' = child level category Thanks