+ Start a Discussion

How to show unique values based on a different object associated with junction object

Hello All, 

I am stuck at a place where I need to show some unique values based on a query. Any help is most welcome.

I have  a junction Object: RP Breach that connects Review Plan and Breach. 

Now in this query I want to show the unique breaches in the rp breaches that each review plan holds. Review Plan to Breach is many to many relationship junctioned by a RP Breach. RP Breach is always unique but same breach can be associated with a unique RP Breach


Review Plan         Rp Breach       Breach
    A                         1111               X
   B                          2222              X  
   C                          3333              X
   D                          4444              X
   E                          5555              O

Now the result in the query should show X,O.

Currently it is showing , X,X,X,X O because it is based on the RP Breach ID which is unique. 

RP Breach has relation with Breach .  And RP Breach has relation with Review Plan. 

We need to show X,O.... But here X is repeated because of RP Breach. How can we query based on The Unique breach associated with the RP Breach.

More Explanation on the above roadblock:

We have review plans, and based on the review plan we are querying RP Breaches. Currently we are getting all RP Breaches related to those review plans. For example,
For 4 Review Plans, we are getting 30 RP Breaches. In those 30 RP Breaches, we are taking unique breaches and showing in the front end. But we need to take the unique breaches available for those review plans.  Because RP Breaches are unique but the Breach Identifiers inside the unique RP Breaches are repeated. This is where I got stuck up.
Here availableRP  means a set of selected review plan IDs. All I am trying to get is the breaches associated with the 4 review plans.
Any help would be highly appreciated.
Sorry I missedd to put the query: The query is:

MappedBreaches  = [select id,name,Breach__c,Breach__r.Shown_in_AddFinding_dropdown_menu__c,Contractual_Provision_s_Breached__c ,Breach__r.Breach_Identifier__c,Category__c,Review_Plan__c,
                   Review_Plan__r.pool__c,Review_Plan__r.Guideline__c,Review_Plan__r.Effective_Date__c,Review_Plan__r.Deal__c from olg_RP_Breach__c where  Review_Plan__c In:availableRp limit 40000];