+ Start a Discussion
Marco RispoliMarco Rispoli 

Inner Joins in SOQL

I am totally new to SalesForce ... I literally just started playing with it 2 days ago. I signed up for a few classes (for next month) in the meanwhile I started playing with queries and I came across a situation that I can't seem to find a solution to: inner joins in SOQL.

Here's the scenario. 

I have this:
Account
and I have this:
AccountPartner
and I want to use this:
 
SELECT *
FROM Account AS ato, AccountPartner AS ap, Account AS afrom
WHERE ap.AccountToID = ato.AccountID
and ap.AccountFromID = afrom.AccountID;

To get this:
Join Result
How do I do it in SOQL?

PS: I dumped data in MS Access and ran the query I just pasted above ... That's where the join result set comes from.

Thank you!!
Swayam@SalesforceGuySwayam@SalesforceGuy
Hi Can You please share the exact object (Table Name) and relationship


--
Swayam
@Salesforceguy
Marco RispoliMarco Rispoli
The objects are Account and AccountPartner. I can query them in the developer console:
 
select AccountToId, AccountFromID FROM AccountPartner

or 
 
select Id, Name from Account

run just fine and return results (that's how was able to populate the tables in the Access database). 

However I can't find any information about the relationship between AccountPartner and Account ... 

Clearly it's there because the IDs are matching up.
Swayam@SalesforceGuySwayam@SalesforceGuy
Hi,


AccountPartner read-only object represents a partner relationship between two Account objects. It is automatically created when a Partnerobject is created for a partner relationship between two accounts.

I think, You won't be able to create joint Query. 

--
Regards,
Swayam
@Salesforceguy

 
Amit Chaudhary 8Amit Chaudhary 8
HI,

Please check below post. I hope that will help you
A Deeper look at SOQL and Relationship Queries on Force.com
https://developer.salesforce.com/page/A_Deeper_look_at_SOQL_and_Relationship_Queries_on_Force.com

Left Inner Join
SELECT Name FROM Position_c WHERE Id IN
(SELECT Position__c FROM	Job_Application__c)
Right Inner Join
SELECT Name,Position__r.Name,
FROM Job_Application__c
WHERE Position__r.Department__c = ‘Sales’

Please let us know if this will help you

Thanks
Amit Chaudhary


 
Pratyush NagPratyush Nag
select id,name from product2 where id in (select Product2id from opportunitylineitem )
this way we can write Inner join