0

I have defined 2 sets investmentTeamIds and teamMemberIds, and I am using these sets in this SOQL query

List<InvestmentTeam__Share> investmentTeamShares = [
            SELECT Id
            FROM InvestmentTeam__Share
            WHERE ParentId IN :investmentTeamIds AND UserOrGroupId IN :teamMemberIds
];

I would like to understand if I use 2 IN clauses like this above, separated with AND, what kind of resultset will appear? Is this kind of inner join?

So let's say that

Set<String> investmentTeamIds = new Set<String>{'A','B','C'};
Set<String> teamMemberIds = new Set<String>{'D','E','F'};

will the query check for both the values in the resultset?

1 Answer 1

0
 ┌───────────────────────────────┐
 │                               │
 │   ParentId    UserOrGroupId   │
 │                               │
 │      A              D         │
 │      B              D         │
 │      C              A         │
 │      F              G         │
 │      G              V         │
 │      A              E         │
 │      B              J         │
 │      G              L         │
 │      R              M         │
 │      T              N         │
 │      C              F         │
 │      E              G         │
 │      T              R         │
 │                               │
 └───────────────────────────────┘

Imagine this table above - essentially the IN clauses are a set of repeated OR clauses.

So you could rewrite your query as:

WHERE ( ParentId = 'A' OR ParentId = 'B' OR ParentId = 'C') AND
      ( UserOrGroupId = 'D' OR UserOrGroupId = 'E' OR UserOrGroupId = 'F')

Which would select row 1, 2, 6 and 11.

Hope that makes sense.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .