10 Creating and Maintaining Joins

This chapter explains how to implement joins using Discoverer Administrator, and contains the following topics:

10.1 What are joins?

In Discoverer, a join relates two folders using one or more matching items. In the database, a join relates two tables using matching columns.

For example, consider the two tables DEPT and EMP.

Figure 10-1 EMP and DEPT tables

Surrounding text describes Figure 10-1 .

Every department in the DEPT table has a department name and a department number. Every employee in the EMP table has a name and belongs to a department (which is identified by its department number).

To see the name of an employee and the name of the department in which they work, you must extract information from both tables. However, before you can extract information from both tables in the same query, a join must exist between the tables.

To define a join, you typically specify one column in one table that matches a column in the other table. In the case of the DEPT and EMP tables, the DEPTNO column in the DEPT table matches the DEPTNO column in the EMP table. In other words, the values in the DEPTNO column in the DEPT table have matching values in the DEPTNO column in the EMP table.

Figure 10-2 EMP and DEPT tables joined using the DEPTNO column

Surrounding text describes Figure 10-2 .

A join typically comprises a master table and a detail table. The master table has one row for which there are many rows in the detail table. In the example above, the DEPT table is the master table and the EMP table is the detail table because each department can have many employees.

The matching column in the detail table is often referred to as the foreign key column.

When you create a join using Discoverer Administrator, you specify a join condition that identifies the item in the master folder and the matching item in the detail folder. It is important to make sure you:

Having defined a join between two folders:

  • Discoverer end users can include items from both folders in the same worksheet in Discoverer Plus (and Discoverer Desktop)

  • you can create complex folders and hierarchies in Discoverer Administrator that contain items from both folders

10.2 What are single item joins?

In Discoverer, a single item join relates two folders by specifying an item that is common to both folders in a join condition. A join condition is the combination of two join items related by a join operator. Typically, the join operator is the equals (=) sign and the join is therefore referred to as an equi-join (for more information about alternative join operators, see "What are non-equi-joins?").

For example, the schema below uses the common column DEPTNO to join the DEPT and EMP tables.

Figure 10-3 Example of two tables joined using a single item join

Surrounding text describes Figure 10-3 .

Every department in the DEPT table has a department name and a department number. Every employee in the EMP table has a name and belongs to a department (which is identified by its department number). To see the name of an employee and the name of the department in which they work, you need information from both the EMP table and the DEPT table.

Imagine that a Discoverer end user wants to see the name of every employee and the name of the department in which they work, as follows:

DNAME ENAME
ACCOUNTS CLARK
ACCOUNTS MILLER
RESEARCH ADAMS
RESEARCH FORD
SALES JAMES

In other words, DEPT.DNAME and EMP.ENAME.

The following SQL statement would achieve the required result:

select dname, ename
from dept, emp
where
dept.deptno=emp.deptno

To enable the Discoverer end user to see the required result, you can do either of the following:

  • You can create a custom folder containing the above SQL statement (for more information, see "How to create custom folders").

  • You can create a join with one join condition (that is, a single item join) between DEPT.DEPTNO and EMP.DEPTNO (for more information, see "How to create joins").

    Having defined the join:

    • In Discoverer Administrator you can create a complex folder, then drag DNAME from DEPT and ENAME from EMP into the complex folder (for more information, see "How to create complex folders").

    • The Discoverer end user can use the complex folder. Alternatively, the end user can select DNAME from DEPT and ENAME from EMP.

10.3 What are multi-item joins?

In Discoverer, a multi-item join relates two folders using more than one join condition, such that the join becomes true when all of the join conditions are met (for more information about join conditions, see "What are single item joins?").

For example, the schema below uses a combination of COUNTRY_CODE and PRODUCT_CODE to uniquely identify products.

Figure 10-4 Example of two tables joined using a multi-item join

Surrounding text describes Figure 10-4 .

Every product in the VIDEO_PRODUCTS table has a description and is uniquely identified by the combination of a country code and a product code (note that product codes are only unique within each country code). Every sale in the VIDEO_SALES table is of a particular product (which is identified by its country code and product code). To see the value of a sale and a description of the product that was sold, you need information from both the VIDEO_SALES table and the VIDEO_PRODUCTS table.

Imagine that a Discoverer end user wants to see the value of each sale and a description of the product that was sold, as follows:

Description Value
UK GAME RENTAL 10
US VIDEO RENTAL 19
FR VIDEO SALES 25
FR GAME RENTAL 8

In other words, VIDEO_PRODUCTS.DESCRIPTION and VIDEO_SALES.VALUE.

The following SQL statement would achieve the required result:

select description, value
from video_products, video_sales
where
video_products.country_code=video_sales.country_code
and
video_products.product_code=video_sales.product_code

To enable the Discoverer end user to see the required result, you can do either of the following:

  • You can create a custom folder containing the above SQL statement (for more information, see "How to create custom folders").

  • You can create a join with two join conditions (that is, a multi-item join) between VIDEO_PRODUCTS.COUNTRY_CODE and VIDEO_SALES.COUNTRY_CODE, and between VIDEO_PRODUCTS.PRODUCT_CODE and VIDEO_SALES.PRODUCT_CODE (for more information, see "How to create joins").

    Having defined the multi-item join:

    • In Discoverer Administrator you can create a complex folder, then drag DESCRIPTION from VIDEO_PRODUCTS and VALUE from VIDEO_SALES into the complex folder (for more information, see "How to create complex folders").

    • The Discoverer end user can use the complex folder. Alternatively, the end user can select DESCRIPTION from VIDEO_PRODUCTS and VALUE from VIDEO_SALES.

Note: A join that uses more than one column in each table to uniquely identify a row is also referred to as a composite join key.

10.4 About joining more than two folders

To join more than two folders in Discoverer, you must define a separate join between each of the folders you want to join.

For example, the schema below uses two joins to relate three tables. One join relates the VIDEO_SALES_ORDERS table with the SALES_ORDER_LINE_ITEMS table and the other join relates the VIDEO_PRODUCTS table with the SALES_ORDER_LINE_ITEMS table.

Figure 10-5 Example of three tables joined using two joins

Surrounding text describes Figure 10-5 .

Every sales order in the VIDEO_SALES_ORDERS table is for a particular customer (and is uniquely identified by a sales id). As shown in the SALES_ORDER_LINE_ITEMS table, every sales order comprises one or more line items and each line item is for a particular product. Every product in the VIDEO_PRODUCTS table has a description (and is uniquely identified by a product id).

Imagine that a Discoverer end user wants to see the customer's name and a description of what they have been buying, as follows.

Customer name Product description
TURNER TOY STORY
TURNER TOY STORY
JONES STARGATE
JONES POPCORN
JONES TRUE LIES
SMITH POPCORN
SMITH TOY STORY
ADAMS STARGATE

In other words, VIDEO_SALES_ORDERS.CUST_NAME and VIDEO_PRODUCTS.PROD_DESC.

The following SQL statement would achieve the required result:

select cust_name, prod_desc
from video_sales_orders, sales_order_line_items, video_products
where
video_sales_orders.sales_id=sales_order_line_items.sales_id
and
sales_order_line_items.prod_id=video_products.prod_id

To enable the Discoverer end user to see the required result, you can do either of the following:

  • You can create a custom folder containing the above SQL statement (for more information, see "How to create custom folders").

  • You cannot use the Discoverer Administrator Join Wizard to create a single join that joins more than two tables. Instead, you must create two separate joins, one between VIDEO_SALES_ORDERS and SALES_ORDER_LINE_ITEMS, and a second between SALES_ORDER_LINE_ITEMS and VIDEO_PRODUCTS (for more information, see "How to create joins").

    Having defined two separate joins:

    • In Discoverer Administrator you can create a complex folder, then drag CUST_NAME from VIDEO_SALES_ORDERS, one item from SALES_ORDER_LINE_ITEMS, and PROD_DESC from VIDEO_PRODUCTS into the complex folder. Having selected the item from SALES_ORDER_LINE_ITEMS, you can subsequently remove the item to get the two item folder you want (for more information, see "How to create complex folders").

    • The Discoverer end user can use the complex folder. Alternatively, the end user can select CUST_NAME from VIDEO_SALES_ORDERS, one item from SALES_ORDER_LINE_ITEMS, and PROD_DESC from VIDEO_PRODUCTS. Having selected the item from SALES_ORDER_LINE_ITEMS, the end user can subsequently remove the item to get the two column worksheet they want.

10.5 What are non-equi-joins?

In Discoverer, a non-equi-join enables you to join two folders where there is no direct correspondence between columns in the tables. A non-equi-join relates two folders using one or more join conditions that use non-equi-join operators.

For example, the schema below uses a non-equi-join to join the EMP and SALGRADE tables because there are no matching columns in the two tables.

Figure 10-6 Example of two tables joined using a non-equi-join

Surrounding text describes Figure 10-6 .

An employee's grade depends on their salary. Employees earning between 700 and 1200 are in grade 1, those earning between 1201 and 1400 are in grade 2, and so on.

Imagine that a Discoverer end user wants to see the grade of each employee, as follows:

ENAME GRADE
KING 5
BLAKE 4
CLARK 4
JONES 4
MARTIN 2
ALLEN 3
TURNER 3
JAMES 1

In other words, EMP.ENAME and SALGRADE.GRADE.

The following SQL statement would achieve the required result:

select ename, grade
from emp, salgrade
where
emp.sal>=salgrade.losal
and
emp.sal<=salgrade.hisal

To enable the Discoverer end user to see the required result, you can do either of the following:

  • You can create a custom folder containing the above SQL statement (for more information, see "How to create custom folders").

  • You can create a join with two non-equi-join conditions, one between EMP.SAL and SALGRADE.LOSAL and the other between EMP.SAL and SALGRADE.HISAL (for more information, see "How to create joins").

    Having defined the join:

    • In Discoverer Administrator you can create a complex folder, then drag SAL from EMP and GRADE from SALGRADE into the complex folder (for more information, see "How to create complex folders").

    • The Discoverer end user can use the complex folder. Alternatively, the end user can select ENAME from EMP and GRADE from SALGRADE.

10.6 What are one-to-many joins, one-to-one joins, and many-to-many joins?

One-to-many joins are the most common type of join. With a one-to-many join, one row in the master folder is joined to multiple rows in the detail folder.

One-to-one joins are joins between two folders where both items used in the join are primary keys. Therefore only one row in one folder will join to only one (or no) rows in the other folder. There is no real master and detail in this case, because each row in the master table can correspond to no more than one row in the detail table. Occasionally, one-to-one joins are a valid construct. Discoverer enables you to specify that a join is a one-to-one join.

It is possible to query a master folder with multiple detail folders (if all but one of the detail folders are joined with one-to-one joins). If more than two detail folders are joined to the master folder using one-to-many joins (also known as a fan trap schema), a row in the master folder might join to many rows in the detail tables, resulting in a Cartesian product. Fan trap schemas are resolved in Discoverer to prevent them returning unexpected results. For more information, see "What are fan traps, and how does Discoverer handle them?".

Many-to-many joins are not supported directly in Discoverer (or in any relational system). However, many-to-many joins can always be reworked and transformed into multiple one-to-many joins. Very occasionally, a many-to-many join is a valid construct.

10.7 About joining two folders using more than one join

You might want to join two folders using more than one join when creating a complex folder. For example, you might create several complex folders that contain the same items, but each complex folder uses one or more joins. Each one of these joins can be defined using different join options.

The following table illustrates how you can join two folders (for example, emp and dept) using four different joins. You can choose one or more of these joins when adding items to complex folders.

Complex folder name Master folder join item Join operator Detail folder join item Join options used for the join
Complex1 emp.deptno = dept.deptno No options selected
Complex2 emp.deptno = dept.deptno Detail foreign key can have null values
Complex3 emp.deptno = dept.deptno One-to-one relationship
Complex4 emp.deptno = dept.deptno Outer join on detail folder

When you create a complex folder and drag items from two folders that have more than one join between the two folders, Discoverer Administrator displays the Choose Joins dialog where you can choose one or more joins to use.

Figure 10-7 Choose Join dialog

Surrounding text describes Figure 10-7 .

For more information, see "How to create complex folders".

When Discoverer Plus or Discoverer Desktop users create worksheets using items from multiple folders, if end users choose items from two folders joined using more than one join, Discoverer does one of the following:

  • Discoverer uses all of the available joins

    This occurs if you select the Disable multiple join path detection option in Discoverer Plus or Discoverer Desktop.

  • Discoverer displays the Join Folders dialog enabling you to select one or more joins

    This occurs if you clear the Disable multiple join path detection option in Discoverer Plus or Discoverer Desktop.

For more information, see the Oracle Fusion Middleware User's Guide for Oracle Business Intelligence Discoverer Plus.

10.8 What effect do joins have on query results and query performance?

In some circumstances, you will always want Discoverer to use a join when querying a master folder and a detail folder. For example:

  • you might want a query to return values from both the master folder and the detail folder

  • you might want a query to return only those rows from the detail folder that have matching values in the master folder

Resolving joins is relatively time-consuming, so returning results from such a query might be relatively slow.

In other circumstances, it will not be necessary for Discoverer to query the master folder and the detail folder. For example:

  • if you know that values in the detail folder always have corresponding values in the master folder

  • if you know that you will always want the query to return all of the detailed values from the detail folder regardless of whether values exist in the master folder

If you set the appropriate option to indicate that Discoverer does not need to query the master folder, query performance will improve. However, be aware that not querying the master table might give you unexpected results. If you are not sure whether to include the master folder, see "Examples of how joins can affect query results from complex folders".

If you combine two or more folders in a complex folder (by using a join), Discoverer can improve query performance by detecting and removing joins that are not required (a process known as join trimming). If the SQLJoinTrim Discoverer registry setting is enabled (that is, if it is set to the default value of 1), Discoverer will remove joins from a query when both of the following conditions are met:

For more information about Discoverer registry settings, see Chapter 21, "Discoverer Registry Settings".

Discoverer will never use a summary folder to satisfy a query that uses a join with the Detail item values might not exist in master folder option selected (for more information, see the "Edit Join dialog: Options tab").

10.9 Examples of how joins can affect query results from complex folders

The examples below assume that you have used Discoverer Administrator to create a complex folder called Emp_and_Dept. The complex folder is based on the DEPT and EMP tables with the join condition DEPT.DEPTNO=EMP.DEPTNO.

Consider the following two scenarios:

  • Scenario One

    In Scenario One, employees in the EMP table must always belong to one of the departments in the DEPT table:

    • the DEPT table contains rows for department 10 (Accounts), department 20 (Research), and department 30 (Sales)

    • the EMP table contains rows for Clark (an employee of department 10), Smith (an employee of department 20), and Allen (an employee of department 30)

    Figure 10-8 Scenario One: An example of a schema where the rows returned do not depend on whether the master folder is included in the query

    Surrounding text describes Figure 10-8 .

    This scenario illustrates a schema in which a query on ENAME produces the same results, regardless of whether you include the master folder in the query.

  • Scenario Two

    In Scenario Two, employees in the EMP table need not belong to a department in the DEPT table, as follows:

    • the DEPT table contains rows for department 10 (Accounts) and department 20 (Research)

    • the EMP table contains rows for Clark (an employee of department 10), Smith (an employee of department 20), and Allen (a former employee of department 30, which no longer exists)

    Figure 10-9 Scenario Two: An example of a schema where the rows returned depend on whether the master folder is included in the query

    Surrounding text describes Figure 10-9 .

    This scenario illustrates a schema in which a query on ENAME might produce different results, depending on whether you include the master folder in the query.

Example 1: Excluding the master folder always possible

You will want to exclude the master folder from a query when including the master folder will either make no difference to the results, or when including the master folder will not return the required results.

Note: Excluding the master folder from a query (that uses only items from a complex folder), means that Discoverer Plus or Discoverer Desktop does not use the join between the master and detail folder. Discoverer does not use the join when you select query items from a complex folder (when creating a worksheet in Discoverer Plus or Discoverer Desktop), and the query items come only from the detail folder (for example, EMP).

Imagine that a Discoverer end user wants to see the name of all the employees in the EMP table by selecting the ENAME item from the Emp_and_Dept complex folder.

In Scenario One, the required results are as follows:

ENAME
CLARK
SMITH
ALLEN

Including the master folder in the query will make no difference to the results because all of the employees will be returned by the query. To improve query performance, you can specify that Discoverer does not query the master folder by selecting the Detail items always exist in the master folder option in the "Edit Join dialog: Options tab". Providing that the SQLJoinTrim Discoverer registry setting is also enabled, Discoverer will not query the master folder (for more information, see Chapter 21, "Discoverer Registry Settings").

In Scenario Two, the required results are as follows:

ENAME
CLARK
SMITH
ALLEN

Including the master folder in the query will only return those employees with department numbers that match department numbers in the DEPT table. But the Discoverer end user wants to see all employees in the EMP table. To return all the employees in the EMP table, you can specify that Discoverer does not query the master folder by selecting the Detail items always exist in the master folder option in the "Edit Join dialog: Options tab". Providing that the SQLJoinTrim Discoverer registry setting is also enabled, Discoverer will not query the master folder (for more information, see Chapter 21, "Discoverer Registry Settings").

Example 2: Excluding the master folder might be possible

You will want to include the master folder in a query when excluding the master folder will not return the required results from the detail table.

Note: Including the master folder in a query (that uses only items from a complex folder), means that Discoverer Plus or Discoverer Desktop uses the join between the master and detail folder. Discoverer uses a join when you select query items from a complex folder (when creating a worksheet in Discoverer Plus or Discoverer Desktop), and the query items come from either the master or the detail folder (for example, DEPT and EMP respectively).

Imagine that a Discoverer end user wants to see the current employees in the EMP table by selecting the ENAME item from the Emp_and_Dept complex folder. Any employees that belong to departments that are not in the DEPT table are not current employees, and are therefore not required.

In Scenario One, the required results are as follows:

ENAME
CLARK
SMITH
ALLEN

Including the master folder in the query will make no difference to the results because all of the employees belong to a department. To improve query performance, you can specify that Discoverer does not query the master folder by selecting the Detail item values always exist in the master folder option in the "Edit Join dialog: Options tab". Providing that the SQLJoinTrim Discoverer registry setting is also enabled, Discoverer will not query the master folder (for more information, see "What are Discoverer registry settings?").

In Scenario Two, the required results are as follows:

ENAME
CLARK
SMITH

Including the master folder in the query will only return those employees with department numbers that match department numbers in the DEPT table, which is exactly what the Discoverer end user wants. You can specify that Discoverer always queries the master folder by selecting the Detail item values might not exist in the master folder option in the "Edit Join dialog: Options tab".

Example 3: Excluding the master folder never possible

You will always want to include the master folder in a query if you want the results to contain information from both the master folder and the detail folder.

Note: Including the master folder in a query (that uses only items from a complex folder), means that Discoverer Plus or Discoverer Desktop uses the join between the master and detail folder. Discoverer uses a join when you select query items from a complex folder (when creating a worksheet in Discoverer Plus or Discoverer Desktop), and the query items come from either the master folder or the detail folder or from both folders (for example, DEPT and EMP).

Imagine that a Discoverer end user wants to see employees and the departments to which those employees belong by selecting the ENAME item and the DNAME item from the Emp_and_Dept complex folder.

In Scenario One, the required results are as follows:

ENAME DNAME
CLARK ACCOUNTS
SMITH RESEARCH
ALLEN SALES

Including the master folder in the query is essential to return the names of the departments. Discoverer will include the master folder in the query even if you have selected the Detail item values always exist in the master folder option in the "Edit Join dialog: Options tab".

In Scenario Two, the required results are as follows:

ENAME DNAME
CLARK ACCOUNTS
SMITH RESEARCH

Including the master folder in the query is essential to return the names of the departments. Discoverer will include the master folder in the query even if you have selected the Detail item values always exist in the master folder option in the "Edit Join dialog: Options tab".

Note that Allen will only be returned (with a null value for the department name) if you select the Outer join on master option in the "Edit Join dialog: Options tab" (for more information, see "What are outer joins?").

10.10 What are outer joins?

Outer joins are SQL constructs that enable you to return rows from one table when there are no matching rows in a table to which it is joined.

Consider the following scenario:

  • the master table DEPT contains rows for department 10 (ACCOUNTS), department 20 (RESEARCH) and department 40 (OPERATIONS)

  • the detail table EMP contains rows for Clark (department 10), Smith (department 20) and Allen (a former employee of department 30, which no longer exists)

Figure 10-10 Master and detail tables DEPT and EMP, where the rows returned are determined by the position of the outer join construct in the query

Surrounding text describes Figure 10-10 .

The following examples use the schema in the above figure to illustrate how the position of the outer join determines the rows returned from a query.

Example 1 - Outer join placed on the master table

Imagine that a Discoverer end user wants to see all employee records, even when an employee does not belong to a department. The required results are as follows:

DNAME ENAME
ACCOUNTS CLARK
RESEARCH SMITH
<NULL> ALLEN

The following SQL statement would achieve the required result:

select dname, ename
from dept, emp
where
dept.deptno(+)=emp.deptno

When the outer join is placed on the master table, the database returns each detail row for which there is no matching master row, and all matching detail and master rows. In the SQL statement, the plus (+) symbol signifies the outer join.

To enable the Discoverer end user to see the required result, you can do either of the following:

  • You can create a custom folder containing the above SQL statement (for more information, see "How to create custom folders").

  • You can create a join with a single join condition between DEPT.DEPTNO and EMP.DEPTNO and select both the Detail items might not exist in the master folder option and the Outer join on master option in the "Edit Join dialog: Options tab" (for more information about creating joins, see "How to create joins").

    Having defined the join:

    • In Discoverer Administrator you can create a complex folder, then drag DNAME from DEPT and ENAME from EMP into the complex folder (for more information, see "How to create complex folders").

    • The Discoverer end user can use the complex folder. Alternatively, the end user can select DNAME from DEPT and ENAME from EMP.

Example 2 - Outer join placed on the detail table

Imagine that a Discoverer end user wants to see all department records even when a department does not have any employees. The required results are as follows:

DNAME ENAME
ACCOUNTS CLARK
RESEARCH SMITH
OPERATIONS <NULL>

The following SQL statement would achieve the required result:

select dname, ename
from dept, emp
where
dept.deptno=emp.deptno(+)

When the outer join is placed on the detail table, the database returns each master row for which there is no matching detail row, and all matching master and detail rows. In the SQL statement, the plus (+) symbol signifies the outer join.

To enable the Discoverer end user to see the required result, you can do either of the following:

  • You can create a custom folder containing the above SQL statement (for more information, see "How to create custom folders").

  • You can create a join with a single join condition between DEPT.DEPTNO and EMP.DEPTNO and select Outer join on detail in the "Edit Join dialog: Options tab" (for more information about creating joins, see "How to create joins").

    Having defined the join:

    • In Discoverer Administrator you can create a complex folder, then drag DNAME from DEPT and ENAME from EMP into the complex folder (for more information, see "How to create complex folders").

    • The Discoverer end user can use the complex folder. Alternatively, the end user can select DNAME from DEPT and ENAME from EMP.

10.11 How to create joins

You create a join to enable end users to include items from different folders in the same worksheet.

To create a join:

  1. Display the "Workarea: Data tab" and select the item in the master folder that will match an item in the detail folder.

    Tip: For more information about which is the master and detail folder, see "What are joins?".

  2. Choose Insert | Join to display the "Join Wizard: Step 1 dialog".

    The master item is displayed in the Master Items field.

    Figure 10-11 Join Wizard: Step 1 dialog

    Surrounding text describes Figure 10-11 .

    Tip: If you want to change the folder and item in the Master Items field, choose the More items option at the bottom of the drop down list.

  3. Click the Operator down arrow and select a join operator from the drop down list to specify the join type.

  4. Click the Detail Items down arrow to display the "New Join dialog".

  5. Select the folder and the detail item for the join.

    You can choose a detail item from a folder in the same business area or in any other open business area.

    By specifying a master item, a detail item, and a join operator, you have created a join condition. Joins that have only one join condition are referred to as single-item joins (for more information, see "What are single item joins?").

    Tip: If you want to change the folder and item in the Detail Items field, choose the More items option at the bottom of the drop down list.

    In some circumstances, you will need to create more than one join condition (for more information, see "What are multi-item joins?").

  6. (optional) To create a multi-item join:

    1. Click Add to display a new row for a new join condition.

    2. Use the drop down lists for Master Items and Detail Items to select a new pair of items from the same master and detail folders as the previous join condition.

      Note: If you specify a master or detail item from a folder that was not included in the previous join condition, the previous join condition is removed.

    3. Add new join conditions until you have specified all the matching items in the master folder and the detail folder.

  7. Click Next to display the "Join Wizard: Step 2 dialog".

    Figure 10-12 Join Wizard: Step 2 dialog

    Surrounding text describes Figure 10-12 .
  8. Select the join details for this join as follows:

  9. (optional) Select any of the following options for this join, as required:

    • No outer joins

      Select this option to not create any outer joins, and display all matching master and detail rows.

    • Outer join on detail

      Select this option to display master rows that have no corresponding detail items, and all matching master and detail rows.

    • Outer join on master

      Select this option to display detail rows that have no corresponding master, and all matching detail and master rows. This check box is only available if the Detail item values might not exist in the master folder option is selected.

    • One to one relationship between master and detail

      Select this check box to specify that there is a one to one relationship between master and detail tables.

      Note: Clear this check box if you are creating an outer join.

    For more information about the above options, see:

  10. Click Finish to save the changes and close the dialog.

    Discoverer Administrator creates the join between the two folders. The join icon is shown below both folders in the Workarea.

Notes

  • To include a function or a literal (for example, text string, number, date) in a join, create a calculated item that includes the function or literal you want to use. You can then create a join and specify the item in the join.

10.12 How to view or edit joins

You can view or edit a join using either or both of the following methods:

Both methods are described below.

How to edit a join using the Edit Join dialog

You might want to edit a join using the Edit Join dialog.

To edit a join using the Edit Join dialog:

  1. Select a join on the "Workarea: Data tab" and choose Edit | Edit... to display the "Edit Join dialog: Items tab".

    Figure 10-13 Edit Join dialog: Items tab

    Surrounding text describes Figure 10-13 .
  2. Edit the join name, description, and join conditions as required.

  3. Display the "Edit Join dialog: Options tab".

    Figure 10-14 Edit Join dialog: Options tab

    Surrounding text describes Figure 10-14 .
  4. Edit the join options as required.

  5. Click OK to save any changes you have made and close the dialog.

    To view or edit join properties using the Join Properties dialog:

How to edit a join using the Join Properties dialog

You might want to edit a join using the Join Properties dialog.

  1. Select a join on the "Workarea: Data tab" and choose Edit | Properties to display the "Join Properties dialog".

    Figure 10-15 Join Properties dialog: General tab

    Surrounding text describes Figure 10-15 .

    Tip: You can select more than one join at a time by holding down the Ctrl key and clicking another join. All properties that are common to each selected join are displayed. If the value of a property is not common to all of the selected joins, the Value field is blank.

  2. Make changes as required.

  3. Click OK to save any changes you have made and close the Join Properties dialog.

10.13 How to delete a join

You might delete a join when it is no longer required. For example, you might want to prevent end users creating a worksheet that contains items from two previously joined folders.

Note: When you delete a join, other EUL objects (for example, complex folders) that use the join might also be affected. It is recommended that you export the EUL before you attempt to delete a join.

To delete a join:

  1. Select a join on the "Workarea: Data tab" and choose Edit | Delete to display the "Confirm Delete dialog".

    Tip: You can select more than one join at a time by holding down the Ctrl key and clicking another join.

  2. (optional) To see the objects that might be affected by deleting this join:

    1. Click Impact to display the "Impact dialog".

      Figure 10-16 Impact dialog

      Surrounding text describes Figure 10-16 .

      The Impact dialog enables you to review the other EUL objects that might be affected when you delete a join.

      Note: The Impact dialog does not show the impact on workbooks saved to the file system (that is, in .dis files).

    2. (optional) Select a row in the Impact dialog to view text at the bottom of the list, indicating what affect the current action will have on the EUL object.

    3. Click Close to close the Impact dialog when you have finished reviewing the impact of deleting the join.

  3. Click Yes if you still want to delete the selected join(s).

10.14 What are fan traps, and how does Discoverer handle them?

A fan trap is a group of joined database tables that might return unexpected results. The most common manifestation of a fan trap occurs when a master table is joined to two or more detail tables independently.

Figure 10-17 A simple fan trap schema

Surrounding text describes Figure 10-17 .

Although this construction is relationally correct, you are likely to return incorrect results if you use a straightforward SQL statement to aggregate data points.

However, if you use Discoverer to aggregate the data points, Discoverer will never return incorrect results, provided fan trap detection is enabled. Every query that Discoverer generates is interrogated for potential fan traps. If a fan trap is detected, Discoverer can usually rewrite the query using inline views to ensure the aggregation is done at the correct level. Discoverer creates an inline view for each master-detail aggregation, and then combines the results of the outer query.

For an example of how Discoverer will return correct results when a straightforward SQL statement will return incorrect results, see "Example of a fan trap".

In some circumstances, Discoverer will detect a query that involves an unresolvable fan trap schema, as follows:

  • if the detail folders use different keys from the master for the join

  • if there is a direct join relationship between the detail folders (thereby creating an ambiguous circular relationship)

  • if non-aggregated values are chosen from more than one of the detail folders

  • if more than one detail folder has a separate join relationship to a different master folder

In the above circumstances, Discoverer disallows the query and displays an error message.

In addition, Discoverer controls which columns can be totalled. If a worksheet displays values of items from both the master folder and the detail folder, Discoverer will not total the values together. Instead, Discoverer will display a null to prevent incorrect or unexpected results.

For more information about enabling or disabling fan trap detection in Discoverer, see the Oracle Fusion Middleware User's Guide for Oracle Business Intelligence Discoverer Plus.

10.15 Example of a fan trap

Consider an example fan trap schema that includes a master folder (ACCOUNT) and two detail folders (SALES and BUDGET), as shown below:

Figure 10-18 Example of a fan trap schema

Surrounding text describes Figure 10-18 .

Every account can have several sales figures and several budget figures for each period.

Imagine that a Discoverer end user wants to answer the question, "What is the total sales and total budget by account?". The aggregates (SUM) from the two detail tables come from the same master table (ACCOUNT).

This relatively simply query will produce:

  • correct results if you use Discoverer (provided fan trap detection is enabled)

  • incorrect results if you use a straightforward SQL statement

Producing correct results using Discoverer

To answer the question, "What is the total sales and total budget by account?", Discoverer:

  • selects the name of the account (from ACCOUNT.NAME)

  • calculates the sum of SALES (from SALES.SALES)

  • calculates the sum of BUDGET (from BUDGET.BUDGET)

Discoverer returns correct results, as shown below:

Account Sales Budget
Account 1 400 400
Account 2 130 100
Account 3 200 750
Account 4 300 200

Discoverer interrogates the query, detects a fan trap, and rewrites the query to ensure the aggregation is done at the correct level. Discoverer rewrites the query using inline views, one for each master-detail aggregation, and then combines the results of the outer query.

The following example shows the SQL that Discoverer uses to return the correct results:

SELECT inACC as Name, SUM(inSalesSum) as SALES_SUM, ,SUM(inBudgetSum) as BUDGET__SUM, 
FROM 
(SELECT masterID AS OutMasterIDSales, SUM(SalesDetailsSales) AS inSalesSum
FROM
(SELECT ID AS masterID, NAME AS masterName FROM ACCOUNT) INLineAccount,
(SELECT ID AS SalesDetailId, ACCID AS SalesDetailAccID, SALES AS SalesDetailsSales FROM SALES )INLineSales
WHERE(masterID = SalesDetailAccID(+))
GROUP BY masterID) inner1,
(SELECT masterID AS OutMasterIDBudget, SUM(BudgetDetailBudget) AS inBudgetSum, masterName AS inACC
FROM
(SELECT ID AS masterID, NAME AS masterName FROM ACCOUNT) INLineAccount,
(SELECT ID AS BudgetDetailId, ACCID AS BudgetDetailAccID, BUDGET AS BudgetDetailsSales FROM BUDGET )INLineBudget
WHERE(masterID = BudgetDetailAccID(+))
GROUP BY masterName, masterID ) inner2
WHERE ((OutMasterIDBudget = OutMasterIDSales))
GROUP BY inACC

The result is correct because each sale and each budget is summed individually (one for each master-detail aggregation) and is then combined with a join based on the master key(s).

Producing incorrect results using a straightforward SQL statement

To answer the question, "What is the total sales and total budget by account?", you might consider using a staightforward SQL statement such as the following:

SELECT Account.Name, SUM(sales), SUM(budget) 
FROM 
Account, Sales, Budget
Where 
Account.id=Sales.accid
AND
Account.id=Budget.accid
GROUP BY
Account.Name

This straightforward SQL statement returns incorrect results, as shown below:

Account Sales Budget
Account 1 800 1200
Account 2 130 200
Account 3 600 750
Account 4 600 600

Although the results are relationally correct, they are obviously wrong. For example, the results indicate that the total sales figure for Account 1 is 800 but you can see from the SALES table that the total sales figure for Account 1 is 400 (that is, 100+100+200).

The incorrect results are based on a single query in which the tables are first joined together in a temporary table, and then the aggregation is performed. However, this approach causes the aggregates to be summed (incorrectly) multiple times.

10.16 What to do if you set up a fan trap inside a complex folder

Discoverer warns about fan trap join configurations in complex folders by displaying a message indicating that an invalid join configuration exists. To make sure that Discoverer returns correct results for complex folders, you can edit the Formula property of the detail item and explicitly specify the aggregate formula.

For example, you might set the Formula property of a Sales item in a complex folder, from Sales Fact.Sales to SUM(Sales Facts.Sales), as shown below:

Figure 10-19 Example of an aggregate formula specified for an item in a complex folder

Surrounding text describes Figure 10-19 .

10.17 What to do if you have a data type mismatch in a join

Discoverer does not allow joins between items of different data types (for example, varchar, numeric, or date). However, if you have upgraded from a previous version of Discoverer, an existing join might already exist between mismatched data types. If a join exists between two items with mismatched data types, Discoverer runs the query but displays an error message and does not complete the query. Discoverer also displays an error message if you try to edit a join that contains items that have mismatched data types.

You can create a join between two items that have mismatched data types by following the steps below:

  • create a new item based on the first mismatched item and use conversion functions (for example, to_char(), to_date(), to_number()) to make the new item's data type compatible with the second item

  • create a join between the new item and the second item

For more information, see "Example of how to create a join between two items that have mismatched data types".

10.17.1 Example of how to create a join between two items that have mismatched data types

In this example, you want to create a join between the Calendar Date folder and the Store and Sales Detail folder, using:

  • the Day of Week item from the Calendar Date folder

  • the Transaction Date item from the Store and Sales Detail folder

These two items have mismatched data types, as follows:

  • the Day of Week item's data type is varchar

  • the Transaction Date item's data type is date

To create a join between the two folders using these two items, you must perform the following steps:

10.17.1.1 Step 1: Create a new item that converts the Day of Week item from a varchar to a date data type

The first step is to create a new item that converts the Day of Week item from varchar to a date data type as follows:

  1. Select the Calendar Date folder from the Video Store Tutorial business area.

  2. Choose Insert | Item to display the "New Item dialog".

  3. Type New Day of Week in the Item Name field.

  4. Select the Functions option to display the function folders.

  5. Click the + symbol next to the Conversion folder to display the conversion functions.

  6. Select the TO_DATE function and click PASTE>> to paste the TO_DATE function into the Calculation field for the new item.

  7. Replace the text in the Calculation field between the brackets of the TO_DATE function with the following text:

    Day of Week,Day

    The Calculation field now displays the following text:

    TO_DATE(Day of Week,Day)

  8. Click OK to create the new item.

You have now created a new item that is based on the Day of Week (varchar) item and that has been converted to a date data type.

10.17.1.2 Step 2: Create a join using the new item

Having created a new calculated item of the correct data type, the next step is to join the new item to the Transaction Date item from the Store and Sales Details folder, as follows:

  1. Select the New Day of Week item from the Calendar Date folder.

  2. Choose Insert | Join to display the "Join Wizard: Step 1 dialog".

  3. Click the Detail Items drop down list to display the "New Join dialog".

    The New Join dialog enables you to select the detail folder and item for the new join.

  4. Click the + symbol next to the Store and Sales Details folder to expand the folder's items.

  5. Select the Transaction Date item and click OK to close the New Join dialog.

  6. Click Next to display the "Join Wizard: Step 2 dialog".

  7. Click Finish to accept the default join options and close the Join Wizard: Step 2 dialog.

    Discoverer is able to join the Calendar Date folder with the Store and Sales Details folder using the New Day of Week item and the Transaction Date item because both items have the same data type.