+

Search Tips   |   Advanced Search

UNION clause operation

The UNION clause specifies a combination of the output of two subqueries. The two queries must return the same number of elements and compatible types.

For the purposes of UNION, all EJB types in the same inheritance hierarchy are considered compatible. UNION requires that equality be defined for the element types.

query_expression := query_term [UNION [ALL] query_term]*
 query_term :=  {select_clause_dynamic  from_clause  [where_clause]   [group_by_clause] [having_clause] } | (query_expression) } 

We cannot use dependent value objects with UNION.

UNION ALL combines all results together in a single collection.

UNION combines results but eliminates duplicates.

If ORDER BY is used together with UNION, the ORDER BY must refer to selection expression using integer numbers.


Examples: UNION operation

This example returns a collection of all employee objects of type EmpBean and all manager objects of type ManagerBean where ManagerBean is a subtype of EmpBean.

This example shows a query that is not valid, because EmpBean and DeptBean are not compatible.


Related concepts

  • EJB query language


    Related tasks

  • Use EJB query
  • Use the dynamic query service