Page is a not externally linkable
- Code, Content, and Presentation
-- Databases
---- Selecting items with another item in common


abbeyvet - 1:06 am on Oct 26, 2008 (gmt 0)


I'm not really sure how to phrase what I am trying to do.

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?


Thread source:: http://www.webmasterworld.com/databases_sql_mysql/3773560.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com