UNION Clause

The UNION clause allows obtaining a new view containing the tuples from another two views or queries. This corresponds with the relational algebra union operation but with some differences. In principle, to execute a relational algebra union all the relations must have the same schema, i.e. the same attributes. However, in Virtual DataPort if some of the views have an attribute that the others do not have, this is added to the resulting view (this corresponds to the relational operation called extended union).

Furthermore, in this case the union includes repeated rows, that is, if a row is in two tables, the tuple appears twice in the resulting view. The modifier DISTINCT can be used in the SELECT clause to avoid this.

Specifying Projections in UNION Queries

The fields to be projected from a union view can be indicated in the SELECT statements of Virtual DataPort; see the syntax below.

Syntax for a projection of the result of a union
<union select> ::= <select> [ UNION <select> ]+
    <projected union select> ::= SELECT <select fields> FROM ( <union select> )