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 |
|
Blastrix
Posting Yak Master
208 Posts |
Posted - 2001-06-09 : 13:26:44
|
| I have two tables, and one table that matches them with a many - many relationship. The tables:categories:catIdcatNamecategories_subTypes:subCatIdsubCatNamecategories_matches:catIdsubCatIdI am having trouble with one particular query. What I need is the full list of sub-categories, without duplicate subCatNames. Simple you say, correct? Well here's the twist. If there is a duplicate, then I need to return the one that corresponds to the category that is currently being viewed on the page if it exists. If not, then I need to return the sub category anyways.I have this worked out with a time wasting ASP script, but I would much rather have the SQL do the work for me.Here is what I'm using right now. It returns all of the subcategories, but returns duplicates.SELECT CS.subCatName, CS.subCatId, CM.catId AS catMatchFROM categories_matches CMRIGHT JOIN categories_subTypes CS ON CM.subCatId = CS.subCatIdORDER BY subCatNameHere's a sample of the results:Aprilia 1 1Bimota 2 1blhabhl 41 NULLBMW 3 1Brackets & Bars 4 4Buell 6 1Bultaco 7 1CCM 9 1Ducati 10 1Fairings 11 3Foam 12 4Fuel 13 4Harley - Davidson 15 1Harley - Davidson 15 2Honda 17 1Kawasaki 18 1Kawasaki 18 2Laverda SFC 19 1So in this instance if I were looking in category 1, then I would want the only the first Harley - Davidson, first Kawasaki, and the remaining records.Edited by - blastrix on 06/09/2001 13:32:02 |
|
|
|
|
|