function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
InfoDeliver IncInfoDeliver Inc 

SOQL multiple object matching problem

Is the following case possible to be done by using SOQL.

Custom object have more than 1 feature ( like attributes), 
the relationship is like below.

Custom 1 .. N  feature

We want to recommend product to custom according to the feature.
Generally , 1 product related to multiple feature , like below

Product 1 .. N feature

I want to search the products for one custom, can I use one SOQL to do this search?
Anupam RastogiAnupam Rastogi

I am reiterating your requirement, let me know if I understood correctly.

You wish to use a single SOQL statement to retrieve a Product that has all the features of the Custom selected.

InfoDeliver IncInfoDeliver Inc
Hi, Thank you very much for your quick response.
I want to retrieve all products that fits the custom's feature.

For example,  a custom select the following features,
sport,  ball,  out-door ,  in-door, team play,  game , white color, orange color,  cooking,

we have 3 product , every product 2 or 3 feature
table tennis racket  :   sport,  in-door , ball 
cooking game  :  game, cooking
golf shoes :  out-door ,  white color,  running 

the first 2 products' all features fit to the custom's selection,  this case, the first 2 products are selected here.
The golf shoes's running feature is not in custom's selection, so golf shoes is not selected.

Can I use one SOQL to select the products for one custom in this case?


Sagar PareekSagar Pareek
Hi InfoDeliver 

In your case Feature object is common , you can query upon Feature object to achieve your desired result. 

But first you need to understand the Relationship Queries
InfoDeliver IncInfoDeliver Inc
Hi, Thank you for your reponse. I post the objects and the SOQL. 
I have a problem about the Query's result.

Customer__c : Name, ID
Product__c : Name, ID
Feature__c : Name , ID
CustomerFeature__c : Name, ID,customerID__c , featureID__c
ProductFeature__c : Name, ID, productID__c, featureID__c

1, SELECT ID FROM CustomerFeature__c WHERE customerID__c = 「custome ID」
2, SELECT productID__c FROM ProductFeature__c WHERE featureID__c IN  [ result ID of the above SQL]

The 1st SOQL can select ID correctly , the problem is the second SOQL. 
the 2nd SOQL here will select all products if there is one related feature which fits to custom's feature.
So, "golf shoes" ( refer to above example)  will be selected here.
But, what I want is the select the products which all features fit to custom, so "golf shoes" should be not selected.
Is there any way to select only products which all features fit to custom? 
InfoDeliver IncInfoDeliver Inc
Sorry, I made a mistake about the object relation.
mistake : Product 1 .. N feature  
correct:  Product N ..  N Feature

Sorry to make you confused. 
gsf asd asdagsf asd asda
I'm using this SQL script for my new post. Can you show the full-screen size code of this program? I want to use it for the page (