## Using pre-joins in queries

JReport Designer provides you with the option of choosing whether or not to use the Pre-join feature when creating queries. If you want to use it, you must have this option enabled.

To turn on the Pre-join feature:

1. Make sure Forbid editing data object properties in the Catalog category of the Options dialog is unchecked.
2. Right-click the current data source connection node in the Catalog Browser and select Properties to expand the Properties sheet.
3. Set the Pre-join property of the connection to true.

Then, when you add tables contained in the connection to the query, which have been predefined some join relationship, the pre-joins will be automatically applied to the tables.

Note: If you are using a JDBC connection, you can turn on the pre-join feature in another way:

1. Right-click the connection and select Edit Connection from the shortcut menu.
2. In the Get JDBC Connection Information dialog, switch to the Pre-join tab, check the Pre-join option, and then click OK.

### Creating queries using pre-join

When you create a query using the pre-join feature, the following cases may appear:

- If JReport Designer needs other tables to bridge the tables you have added, you will be prompted to decide whether to add another table to the query. For example,

  Suppose you've added table A and C to your query, a message box will then appear asking you whether you want to add table D in order to create links between tables A and C.

  Note: The prompt message appears only when the option Show warning message when adding tables is selected in the Query Editor category of the Options dialog. Otherwise, JReport will add the bridged table automatically without any prompt.

- If there is more than one paths available in the pre-join, as with this case,

  You've added table A and C to the query, and there are two paths available - ABC and ADC. JReport Designer will ask you for the path ABC or ADC.

  JReport Designer provides two methods for seeing the path information of a query:

  - In the Catalog Browser, expand the Properties sheet and select the query that uses the pre-join path. You will then see a property called Path Name which shows the name of the path used.
  - In the Query Editor window, click the Show Paths button.

### Editing queries using pre-join

One query is bound with at most one path. Once a path has been specified for a query, when you modify the relationships among the tables, you can make changes to a specific query based on that path, but the path itself will not be changed. When you edit a query, the following cases may appear:

- Adding tables to a query that has already been specified a path - If more than one path is suitable after the tables have been added, the specific path will still be used. That is, you cannot choose another path to replace the original one.
- If the path specified for a query is deleted - In the Query Editor, the Show Paths button will be disabled.