Contents Index Tables tab Columns tab

SQL Anywhere Studio Help
  Query Editor Help

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 
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 sales_order:

FROM ("DBA"."customer"
   JOIN "DBA"."sales_order")""
     JOIN "DBA"."sales_order_items"
More information 

Contents Index Tables tab Columns tab