Xnuiem, the code gets very lengthy with this type of query. This is the query that I run for the question that I had previously posted before. I will give you an example:
Table Products { ID, Name }
Table Fruit { ID, Name }
Table Products_Fruit { ID, Products_ID, Fruit_ID }
Sample Data:
Products -
Record 1: [1, Bowl]
Record 2: [2, Jar]
Fruit -
Record 1: [1, Apple]
Record 2: [2, Pear]
Record 3: [3, Orange]
Record 4: [4, Grape]
Products_Fruit -
Record 1: [1, 1 (Bowl), 1 (Apple)]
Record 2: [2, 1 (Bowl), 2 (Pear)]
Record 3: [3, 1 (Bowl), 4 (Grape)]
Record 4: [4, 2 (Bowl), 2 (Pear)]
Basically this is what I am trying to accomplish.
"Give me all the products that contain Pear and Orange"
I thought I would the following: SELECT DISTINCT(Products_ID) from Products_Fruit WHERE Fruit IN (2, 3);
The output shows 1 and 2 as the products. It should really show only 1.
If I do a query like the following it works:
SELECT DISTINCT(Products_ID) FROM Products_Fruit a, Products_Fruit b where a.Fruit = 2 and b.Fruit = 3 and a.Products_ID = b.Products_ID
The problem with the above query is that it is not feasbile for a huge number of options.
This is just an example, my real query can expand to be really big.
I hope this helps. I appreciate your help Xnuiem.
|