Selecting columns from multiple tables
550881Dec 9 2006 — edited Dec 11 2006Hello,
I'm currently learning SQL and am having difficulty trying to do something that in my head seems simple enough. I will try my best to describe what my schema is like:
- SKU table contains a list of products: OID column is the primary key; NAME column contains the product name
- CAT table contains a list of categories: OID column is the primary key; PARENT_OID column links to another record in the CAT table that represents the parent category; NAME column contains the category name
- MAP table maps products to their categories: OID column is populated by the SKU table's primary key; PARENT_OID column is populated by the CAT table's primary key and represents the category that the product is under
A pretty simple shema, right? Now here's the result set that I'm trying to get: joining all three tables, I would like to return a reset set with the following columns:
1. Product name (SKU.NAME)
2. Name of category containing product (CAT.NAME)
3. Name of product's grandparent category (i.e., parent of category containing product)
I'm able to get a result set with the first two columns, but I can't find a way to select the third column. Is there a way to use the PARENT_OID value from the CAT table to retrieve the category name of that category's parent category and then return it in the same result set?
TIA,
Tom