It sounds like you're asking for two different things - a tagging system and a hierarchical categorization system. Most tagging systems I've seen allow you to tag a resource with any number of tags, but in general, tags aren't related in any way.
Storing a hierarchy in a database is an old problem with many solutions. I have found this one to be particularly interesting because it allows the query of full branches with a single query (trade-off being slower inserts):
http://mrnaz.com/static/articles/trees_in_sql_tutorial/