0

What are the key differences between SOQL Joins and SQL Joins?

  • 1
    I've rewritten the actual question text to be in a format that invites proper answers, but I still feel it is overly broad for this site. Perhaps other community members will disagree. When you ask something like could anyone help or could someone compare X and Y, the straightforward answer is actually just yes or no. That style of question doesn't actually ask for the information you seek. – Adrian Larson Mar 21 '17 at 12:41
  • The Q is still 'On hold' from what I understand from the help center it will be closed automatically if not reopened, What I want to ask in this question Is give an example of SOQL Joins compared to SQL Joins, I master SQL more than SOQL for now, and I am sure there is people out there with a good SQL knowledge switching to SFDC and want to get a comparaison between the two. I wanted to document that on SFDC Stack, as I understand it's recommended to ask question an answer it, Thanks – benahm Mar 22 '17 at 8:48
2

Below is a comparison inspired by A Deeper look at SOQL and Relationship Queries on Force.com.

(We suppose that we have an Account & Contact tables in a SQL database with the column Account as foreign key from Contact to Account)

Right Outer Join

SOQL:

SELECT FirstName, LastName, Account.Name FROM Contact

SQL:

SELECT con.FirstName, con.LastName, acc.Name 
FROM Contact con
RIGHT OUTER JOIN Account acc ON con.Account=acc.Id

Left Outer Join

SOQL:

SELECT Name,(SELECT FirstName,LastName FROM Contacts) FROM Account

SQL:

SELECT acc.Name, con.FirstName, con.LastName
FROM Contact con
LEFT OUTER JOIN Account acc ON con.Account=acc.Id

|improve this answer|||||

Not the answer you're looking for? Browse other questions tagged or ask your own question.