Forum Moderators: open
Heres the scenario. A MySQL database has a table with 2 columns, neither unique : a list of product IDs and a list of category IDs. Basically it's indicating additional categories in which products should appear, apart from their main cat.
So, say like this:
pID ----- pCat
a ------- 1
a ------- 2
a ------- 5
a ------- 6
b ------- 2
b ------- 3
b ------- 4
b ------- 5
c ------- 1
c ------- 2
c ------- 7
c ------- 8
What I want to do is this.
I want to extract a list of all categories associated with any products that are listed as being in a specified category, let's say pCat 1.
So for example in this case my list would include 1,2,5,6,7 and 8 - but not 3 or 4, since they are only associated with pID b, which is not in cat 1.
Does that make sense? Is it possible?
I haven't tested this but this should get you all the CatID's that have a one-to-many relationship with pID
"this should get you all the CatID's that have a one-to-many relationship with pID"
That's not what I am looking for though.
I know I haven't explained this well, but I won't have a pID to begin with in this scenario, I will only have a single CatID.
I need to take that single known CatID, get a list of pIDs it is related to, then extract all the other catIDs related to those, and only those, pIDs.
This table has many-to-many relationships and is one that I'm stuck with and can't change - but if I could figure this out it would be seriously life enhancing!