# Union queries

You may note that hibernate's HQL does not allow unions, as this does not reconcile with the object-oriented approach of HQL. However, as this can be a common technique to apply, a programmatic union has been provided in the Oracle Utilities Application Framework. The application will open two cursors and flip back and forth between rows from each cursor when each would be the next one, based upon the order by clause. This should at most read one extra row from each cursor opened than may be needed (in the case of limited maximum rows).

To union two queries, they must have identical result columns, order by clauses, and max rows setting. Note that some of the properties of the union query be modified directly, leaving the individual queries to omit those properties.

Creating a union query is simple. Given two queries that need to be unioned together, simply issue:

`UnionQuery union = query.unionWith(query2);`

If a third (or later) query needs to be unioned, add it to the union directly:

`union.addQueryToUnion(query3);`

Parent topic: HQL Programming Standards