The following blog by Peter is one of the best blog I have found:
Thursday, June 15, 2023
All the aot query joins in dynamics 365 FO X++
In this blog of Dynamics Community 101 we will learn about AOT query joins in Dynamics 365 F&O X++
Here are the different types of joins you can perform in X++:
1. Inner join: The inner join is the most common type of join. It returns rows from both tables where there is a match. If there is no match, the row is not included in the result set.
select custTable
join custTrans
where custTable.AccountNum == custTrans.AccountNum;
2. Outer join: The outer join returns all the rows from one table, and matched rows from the other table. If there is no match, the result is null on the side of the table that doesn't have a match.
select custTable
outer join custTrans
where custTable.AccountNum == custTrans.AccountNum;
3. Exists join: The exists join returns rows from the first (or left) table for which there is a matching row in the second (or right) table.
select custTable
exists join custTrans
where custTable.AccountNum == custTrans.AccountNum;
4. NotExists join: The not exists join returns rows from the first (or left) table for which there is no matching row in the second (or right) table.
select custTable
notexists join custTrans
where custTable.AccountNum == custTrans.AccountNum;
Example:
The inner join will still only return records where there is a match in both tables. However, because the DeptId 10 appears twice in the Departments table, the employee with DeptId 10 will appear twice in the result:
2. Outer Join
The outer join will return all records from the Employees table and the matching records from the Departments table. The employee with DeptId 10 will appear twice, and the employees with DeptId 40 and 50 will have null for DeptName:
3. Exists Join
The exists join will return records from the Employees table for which there is a matching record in the Departments table. Because the exists join only checks for the existence of a match, the duplication in the Departments table doesn't affect the result:
4. NotExists Join
The not exists join will return records from the Employees table for which there is not a matching record in the Departments table. This result is also unaffected by the duplication in the Departments table:
Current date time Dynamics 365 FO
utcdatetime now = DateTimeUtil::applyTimeZoneOffset(datetimeutil::utcnow(), DateTimeUtil::getUserPreferredTimeZone());