Using multiple tables in a query page 1 |
|||||||||||||||||||||||||||||||||||||||||||||||||||
The SELECT statement syntax given at the end of the previous chapter shows that more than one table may be pointed in the FROM clause. A table listing that does not use WHERE clause is practically unused because this produces the relational operation of the Cartesian product of the tables involved. That is, each record in one table meshes with each record in another table. For example, the tables
As a rule, the table listing is used with the condition of joining records from different tables in the WHERE clause. The condition for the above tables may be a coincidence of the values, say, in the columns a and c:
Now the result set of that query is the following table:
i.e. only those table rows that have equal values in specified columns (equi-join) are joined. Although some arbitrary conditions may be used, nevertheless the equi-join is most commonly used because this operation reproduces a certain entity split by two entities as a result of a normalization process. Even though different tables have columns with the same names, the dot notation is needed for uniqueness: In cases where ambiguity is not available, that notation need not be used.
|