Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » SQL Anywhere 10 - Context-Sensitive Help » Query Editor Help

Tables tab Next Page

Joins tab


Use this tab if you have more than one table in your query.

When you include more than one table in a query, the tables must somehow be joined. This tab allows you to define your joins.

Default joins

When you specify tables in the Tables tab, the Query Editor tries to generate a default join condition. It does this for two reasons. First, the Query Editor processes the query as you create it. If there is no default join, the tables create a cross product, and this can result in slow processing. Secondly, the Query Editor suggests a join strategy that might work for you.

If you add tables in the Query Editor Tables tab, the Query Editor checks to see if a foreign key relationship has been created between the tables. If there is one foreign key, it uses it to generate an ON condition. If there is more than one foreign key relationship, it uses the first one it finds. If there are no foreign keys, it does not generate an ON clause and the tables become a cross product.

You can always review your query by clicking the SQL tab, which is located at the bottom of the Query Editor dialog. You can edit your join strategy directly on the SQL tab, or you can use the Joins tab user interface to change it.

For more information about key joins, ON conditions, and cross products, see Joins: Retrieving Data from Several Tables.

Tip: All the fields in the Joins tab are resizable. You can also expand the Query Editor by pulling on its edges. You may need to resize the fields and dialog in order to read your table names.

Dialog components

Left table expression    Select a table from the dropdown list. Only tables that have been entered in the Tables tab are available. Placing a table on the right or left is significant for outer joins.

Join type    Select a join type from the dropdown list.

See Joined tables.

Right table expression    Select a table from the dropdown list. Only tables that have been entered in the Tables tab are available. Placing a table on the right or left is significant for outer joins.

Condition    Double-click to create an ON condition, if desired. The Query Editor inserts the keyword ON. For key joins and natural joins, the ON condition is generated by SQL Anywhere.

For information about ON conditions, see Explicit join conditions (the ON clause).

Add/Delete    Use to add or delete lines. Click the gray circle to the left of the line to select the line.

You must delete blank lines. This does not affect the tables in your query: to add or delete a table, use the Tables tab.

Results    This pane displays the results of your query, or an error message if the query contains errors.

SQL    Click SQL at the bottom of the dialog to see the SQL code for your query.

Using the joins tab

When you add more than one table to a query, the Query Editor attempts to create a default join strategy. If it cannot find a foreign key relationship between the tables, the default is a cross product. In most cases, cross products are not desirable.

To add or edit the join strategy, choose a table, a join type, and another table, all from the dropdown lists. Alternatively, click the SQL tab and edit the code directly.

Troubleshooting

If you receive an error message indicating that your join is not correct, click the SQL tab at the bottom of the window to review the SQL code. It may happen that empty quotation marks or extra commas have been inserted in your code, particularly if you have added and deleted lines on the Join tab. For example, the following query produces an error message. You need to delete the empty quotes that appear after SalesOrders:

FROM ("Customers"
   JOIN "SalesOrders")""
     JOIN "SalesOrderItems"
More information