sql - Name of parent category with parent_id -
i working on quiz question , have hit wall on how solve problem. problem follows:
"write sql query lists film categories category_id, category's name (called category) , parent category's name (called parent), ordered alphabetically category's name."
the entity category has category_id, name , parent_cat(which id of category)
this query have far:
select a.category_id, a.name category, (select b.name a.parent_cat=b.category_id , a.parent_cat not null) parent "category" a, "category" b a.parent_cat not null order a.name
unfortunately returning duplicate instances of category of instances having null values "parent"
any advice appreciated!
select a.category_id, a.name category, b.name parent "category" join "category" b on a.parent_cat=b.category_id a.parent_cat not null order a.name
Comments
Post a Comment