So I have a category table set. There is a field named "id", "name", "fk_parent_cat_id" (and more) within this table. "Fk_parent_cat_id" basically just connects a specific category to a parent group.
Okay. It's being said, how I capture information on a category that is a query, but it also captures information on the parent category. My main concern is that I am only grabbing the parent ID, which is good, but I do not need to run another query to identify the parent class name.
A general query result
id: 2 name: category 1 fk_parent_cat_id: 1
And, I should have the result
id: 2 name: category 1 fk_parent_cat_id: 1 fk_parent_cat_name: top class
Does this question seem to understand? I think there is a way to do this so that anyway ...
Thanks for any epithet!
You can complete this with Inner Join just to make sure that your table and foreign key columns The names are in your database (because you have not provided any information about the column names in the parent category table). Keep in mind that if you have a single category table (i.e. all your categories are stored in one table) then there is nothing wrong in joining itself to the same table - you need to name the names of the tables in your query. The need is sure they are not ambiguous.
Select C.id, C.name, C.category, P.parent_cat_name Child Credential C Inincluded ParentCategory P on C.fk_parent_cat_id = P.parent_cat_id
No comments:
Post a Comment