When you add two (or more) tables to a query, the Query Designer attempts to join them based on common data or on information stored in the database about how tables are related. (For details, see Joining Tables Automatically.) However, if the Query Designer has not joined the tables automatically, or if you want to create additional join conditions between tables, you can join tables manually.
You can create joins based on comparisons between any two columns, not just columns that contain the same information. For example, if your database contains two tables, titles
and roysched
, you can compare values in the ytd_sales
column of the titles
table against the lorange
and hirange
columns in the roysched
table. Creating this join would allow you to find titles for which the year-to-date sales falls between the low and high ranges for the royalty payments.
Tip Joins work fastest if the columns in the join condition have been indexed. In some cases, joining on unindexed columns can result in an extremely slow query. For information about creating indexes using the Visual Database Tools, see Indexes.
To manually join tables
Note The join columns must be of the same (or compatible) data types. For example, if the join column in the first table is a date, you must relate it to a date column in the second table. On the other hand, if the first join column is an integer, the related join column must also be of an integer data type, but it can be a different size. The Query Designer will not check the data types of the columns you use to create a join, but when you execute the query, the database will display an error if the data types are not compatible.
The Query Designer adds an INNER JOIN clause to the SQL statement in the SQL pane. You can change the type to an outer join. For details see Creating Outer Joins.