Report Designer: Joins

 Caution
The Joins window is recommended for advanced users only.

Joins describe how the data objects on a report are related to each other. When two objects are joined, a field in the first data object is associated with a field in the second data object. Wherever a value in the first data object's field matches a value in the second data object's field, that value's rows from each data object come together to form a composite row. The table produced by all the composite rows is the resulting data that appears on the report.

For example, take the following data objects, Orders and Products. The Orders.ProductId field corresponds with the Products.Id field. When the data objects are joined from Orders.ProductId to Products.Id, the rows are connected wherever those two fields have matching values.

Data objects joined on Orders.ProductId >> Products.Id

The result of this join is the following composite rows. These data objects have a one-to-one relationship, because each row in the "left" data object joins at most one row in the "right" data object.

Joined data objects. Products.Id is omitted.

 Tip
Data Objects could be joined along more than one set of fields; composite rows are formed only when all sets have matching values.

For two data objects to be co present on a report, there must be a join path between them. They are either directly joined, or there is a path through one or more intermediate objects. You do not have to configure joins manually - they already exist in the environment. However, if you want to learn how to add or adjust joins on a per-report basis, this topic will explain the options that are available.

Join Types

The join that was previously described is the most common type of join, an inner join. When an inner join is applied, rows in either data object that have no matching row in the other are excluded from the resulting table. However, you may not want to exclude these rows. To do so, you can change the type of join to an outer join.

For example, the row in the Products data object with Id: 12 has no matching row in the Orders data object. With an inner join, this row is excluded from the output. If you want to see the Products rows that have no matching Orders row, you can change the join type.

To do so, on the toolbar, click  Advanced, then click  Joins to open the Joins dialog, select the Products data that does not have Orders data check box.

Left outer join

This changes the join between these objects to a left outer join, because all rows from the left data object are included. The following rows result:

Joined objects with all Products rows. Products.Id is omitted.

Similarly, selecting the Orders data that does not have Products data check box changes the join to a right outer join, which includes all rows from the right data object. Selecting both check boxes includes all rows from both data objects; this is a full outer join.

Relationship Types

There are two types of join relationships: one-to-one and one-to-many.

In the previous example, the relationship between the data objects is one-to-one, because each row in the left data object joins at most one row in the right data object. Some objects have a one-to-many relationship, where each row in the left data object joins zero or more rows in the right data object.

A one-to-many relationship from data objects  X to Y is represented in the following diagram:

Each X is joined to one or more Y

Reports with a single one-to-many join are well suited to grouping by the left data object. The data in these reports is generally well-formed and understandable.

However, when a report has multiple data objects with one-to-many joins, data can appear more disorganized and confusing. For example, the following diagram represents data from three data objects, X, Y, and Z, where the relationships between X - Y and X - Z are both one-to-many:

Each X has 1 or more Y, and 1 or more Z

Because Y and Z are not directly related to each other, there are many rows with only Y or only Z. This can cause the report to be significantly larger, and to be difficult to read and interpret. This occurs even with inner joins, the most restrictive type, because by default there is no logic that deals with the relationship between Y and Z.

Read on for different ways of improving the structure of a report with multiple one-to-many joins.

Cartesian Processing 

You could fill the blank spaces with supplementary data by disabling Special Cartesian Processing from the Joins window. Blank cells are filled in with data that is repeated directly from the previous row. The following diagram demonstrates how this works:

Disabling Special Cartesian Processing

The shaded cells represent data that has been repeated from the previous row. This can make the report more readable. However, this approach poses a problem: Blank cells indicate a lack of a relationship between two fields, so filling in these spaces with artificial data can obfuscate any relationship between Y and Z. This can decrease the accuracy of the report.

There are better ways to improve the readability of such a report without sacrificing accuracy:

Must Constraints

Although Y and Z are not directly joined, they are both related to X, so there is an implicit relationship between them. If you examine Y and Z alone, you will notice that they technically exhibit a full outer join.

Y and Z, without X

Because all the rows from Y and Z that relate to X are shown, there are rows with both Y and Z, or with only one of either. Must constraints allow you to change the implicit join type, and in doing so, eliminate rows that lack data from one or both data objects.

To set Must constraints, from the Joins window, locate the MUST panel for the applicable data objects:

Setting Must constraints

Do one of the following:

          

Effect of setting various Must constraints

Modifying Joins

The Joins dialog shows all direct and implicit joins on the report. Direct joins can be added, modified, or removed from the report.

the Joins dialog showing 2 joins, an outer join selector and Special Cartesian Processing dropdown

To add a new join:

  1. Select From and To data objects.

  2. Click  Add.

  3. Click  Add Condition then select From (left column) and To (right column) fields.

     Note
    If there are multiple conditions, only the rows that satisfy all the conditions are joined.

  4. Click Okay.

To remove conditions, click the Delete  icon next to the condition to delete.

To modify a join's fields:

  1. Click the Edit  icon next to the join to edit.

  2. Add, remove, or modify conditions.

  3. Click Okay.

To remove a join, click the Delete  icon next to the join to delete, then click Okay.

To restore the default joins, click  Recreate, then click Okay.

Advanced Joins

You may be able to specify join conditions that are more complex than column equality.

Type

Instead of joining between two columns, one or both sides of the join may instead be an arbitrary expression, constant, or SQL sub-query that you specify.

To change the expression type for one side of a join condition, select one of the following from the Type list:

Then enter the value in the Value field.

Operator

As opposed to the default equality (=) operator, which joins fields from the left expression to matching fields from the right expression, a join condition can use one of several alternative operators instead. For example, the inequality (!=) operator joins fields on the left to non-matching fields on the right. To do so, select one of the alternative operators from the Operator list:

Grouping

When a join has two or more conditions, you can specify how the conditions should be met as a group in order for the join to take effect.

To specify that either one of two conditions will satisfy part of the clause, select OR from the Conjunction list for the first condition of the two.

To add parentheses around two conditions, select the Group check box for the first condition of the two.

You can preview the full join clause in the Summary field.