Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Whamoduck
Starting Member
3 Posts |
Posted - 2004-09-24 : 11:26:44
|
| First - Thanks for taking the time to look at my question and offering asistance.Issue:One company can have multiple categoryID's and I need to display them on one line as Industry, Category and Sub category. There is a relation ship that is based on the ParentID and CategoryID from Table C you will be able to see when you view the example data.I have outlined the data below to try and give you a picture and have included my sql code at the bottom that returns 3 rows for company 12345 and returns 2 rows for company 67890.I need the data to display as follows:CompanyId - CompanyName - Industry - Category - SubCategory12345 - ABCDE - Automotive - Auto Repair - All Repairs67890 - VWXYZ - Home Serice - LandscapeTable A: companyFields: CompanyId, CompanyName;Table B: categoryFields: CompanyId, CategoryIdTable C: ref_categoryFields: CategoryId, ParentId, NameTable A company dataCompanyId CompanyName12345 ABCDE67890 VWXYZ Table B category dataCompanyId CategoryId12345 1 (This is the industry level)12345 1002 (This is the category level)12345 2330 (This is the sub category level)67890 7 (Industry level)67890 1063 (Category level) Table C ref_category dataCategoryId ParentId Name1 0 Automotive1002 1 Auto Repair2001 1002 All Repairs7 0 Home Services1063 7 LandscapeThe SQL I have so far that does not return 1 record for each companyid.SELECT comp.Name, cat.companyID, cat.CategoryID, ref_cat.categoryID, ref_cat.parentID, ref_cat.nameFROM company as compjoin category as cat on cat.companyid = comp.companyidjoin ref_category as ref_cat on ref_cat.categoryId = cat.categoryIDWhere comp.companyID in (12345, 67890)Order by comp.CompanyId |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-09-24 : 12:05:02
|
| read up on GROUP BY in books-on line if you need to learn about how to summarize your data.- Jeff |
 |
|
|
Whamoduck
Starting Member
3 Posts |
Posted - 2004-09-24 : 12:09:37
|
I am thinking this is going to have more to do with alias tables than grouping. Could you explain how you think group by would solve this issue.quote: Originally posted by jsmith8858 read up on GROUP BY in books-on line if you need to learn about how to summarize your data.- Jeff
|
 |
|
|
|
|
|