Join, Projection and Selection 

The structure of a view with the relational operators join, projection and selection and data selection using this view will be demonstrated with a simple example.

Given two tables TABA and TABB. Table TABA has 2 entries and table TABB has 4 entries.

The tables are first attached to each other. Each record of TABA is combined with each record of TABB. If a join condition is not defined, the cross product of tables TABA and TABB can be displayed with the view.

Join Conditions

The entire cross product is not usually a sensible selection. The cross product must therefore be restricted with join conditions. A join condition describes how the records of the two tables are connected.

In our example, Field 1 of TABA must be identified with Field 3 of TABB. The join condition is therefore TABA-Field 1 = TABB-Field 3. This join condition removes all records for which the entry in Field 1 is not identical to the entry in Field 3 from the cross product. The column for Field 3 in the view is not required.

The join condition can be specified explicitly during view maintenance. It is also possible to use an existing foreign key. The join condition is automatically generated from the definitions in the foreign key ( Foreign Key Relationship and Join Condition).

Projection

Sometimes some of the fields of the tables involved in a view are not of interest. The set of fields used in the view can be defined explicitly (projection).

In our example, Field 4 is of no interest and can be hidden.

Selection Conditions

Selection conditions that are used as a filter can be defined for a view.

Restrictions can be defined for the fields of the view in these selection conditions. In this case, only the data records that satisfy the restrictions are used in the view. In such selection conditions, a field of the view is compared with a constant using a comparison operator. Several such selection conditions can be linked with the logical operators AND and OR.

In our example, only the records that have the value A in Field 4 should be displayed with the view. In this case the selection condition is therefore TABB-Field 4 = 'A'.

A selection condition can therefore be formulated with a field that is not contained in the view.

See also:

Inner and Outer Join