Join, Projection and Selection
This example shows the structure of a view with the relational operators join, projection and selection.
Given two tables TABA and TABB. Table TABA has 2 entries and table TABB has 4 entries.
Each record of TABA is first combined with each record of TABB. If a join condition is not defined, the cross product of tables TABA and TABB is displayed with the view.
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.
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 that are used as a filter can be defined for a view.
Restrictions can be defined for the contents of the view fields in selection conditions. In this case, only the data records that satisfy these restrictions can be selected with the view. In a selection condition, the contents of a view field are compared with a constant using a comparison operator. Several 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 Join and Outer Join