---
title: "Run a union query"
id: "run-a-union-query"
project: "EHR User Guide"
url: "https://help.cloud5.com.au/articles/ehr-user-guide/run-a-union-query"
updated: 2026-10-19T00:54:08Z
---

# Run a union query

Union queries combine the results of two or more queries into one set of results. They are most often used when it's not possible to return the full set of results from a single query.

You can only create a union query using another accessible public query.

Both queries must exist and both queries must have the same number of fields (and the same number displayed), with corresponding data types.

* * *

| **Case study: union queries**<br><br>Harry creates a query that displays 5% salary increase for employees in the **pg04**payroll.<br><br>Harry also runs a query that displays a 10% salary increase for all employees in the **pg05**payroll.<br><br>He wants the results for both the **pg04**and **pg05**payrolls to display jointly. |
| --- |

**Query 1**
Harry creates the first query, calling it **Rate Increase 5%**...
[+] [Show example: rate increase 5% query](javascript:void%280%29)
 [-] [Hide example: rate increase 5% query](javascript:void%280%29)
 ![](/resources/Storage/ehr-user-guide/run-a-union-query/union%20query%20-%20sal%20inc%205.1.png)

Harry includes two calculated fields, **Increase** and **New Rate**, in the query...
[+] [Show example: calculated fields](javascript:void%280%29)
 [-] [Hide example: calculated fields](javascript:void%280%29)
 ![](/resources/Storage/ehr-user-guide/run-a-union-query/union%20query%20-%20sal%20inc%205.2%263.png)

### 

### He applies an advanced filter to extract data in **pg04** payroll...
[+] [Show example: advanced filter](javascript:void%280%29)
 [-] [Hide example: advanced filter](javascript:void%280%29)
 ![](/resources/Storage/ehr-user-guide/run-a-union-query/union%20query%20-%20sal%20inc%205.4.png)

### Harry runs the query...
[+] [Show example: rate increase 5% query results](javascript:void%280%29)
 [-] [Hide example: rate increase 5% query results](javascript:void%280%29)
 ![](/resources/Storage/ehr-user-guide/run-a-union-query/union%20query%20-%20sal%20inc%205.5.png)

**Query 2**

Now Harry creates the second query by saving a copy of the first query and calling it **Rate Increase 10%**...
[+] [Show example: rate increase 10% query](javascript:void%280%29)
 [-] [Hide example: rate increase 10% query](javascript:void%280%29)
 ![](/resources/Storage/ehr-user-guide/run-a-union-query/union%20query%20-%20sal%20inc%2010.1.png)

He changes the calculated fields, **Increase** and **New Rate**, in the query...
[+] [Show example: calculated fields](javascript:void%280%29)
 [-] [Hide example: calculated fields](javascript:void%280%29)
 ![](/resources/Storage/ehr-user-guide/run-a-union-query/union%20query%20-%20sal%20inc%2010.2_3.png)

Harry applies an advanced filter, this time, to extract data in **pg05** payroll...
[+] [Show example: advanced filter](javascript:void%280%29)
 [-] [Hide example: advanced filter](javascript:void%280%29)
 ![](/resources/Storage/ehr-user-guide/run-a-union-query/union%20query%20-%20sal%20inc%2010.4.png)

Harry runs the query...
[+] [Show example: rate increase 10% query results](javascript:void%280%29)
 [-] [Hide example: rate increase 10% query results](javascript:void%280%29)
 ![](/resources/Storage/ehr-user-guide/run-a-union-query/union%20query%20-%20sal%20inc%2010.5.png)

**Union query**

Now, to create a union query, from the Filter tab of the **Rate Increase 10% query**, he clicks **Union Query** and selects the **Rate Increase 5%**query...
[+] [Show example: select query to union](javascript:void%280%29)
 [-] [Hide example: select query to union](javascript:void%280%29)
 ![](/resources/Storage/ehr-user-guide/run-a-union-query/union%20query%20-%20sal%20inc%2010%20to%205.png)

Harry runs the union query...
[+] [Show example: union query results](javascript:void%280%29)
 [-] [Hide example: union query results](javascript:void%280%29)
 ![](/resources/Storage/ehr-user-guide/run-a-union-query/union%20query%20-%20sal%20inc%2010%20to%205%20results.png)

* * *

## Create and run a union query![](/resources/Storage/ehr-user-guide/ehr-user-guide/icons/desktop%20icon.png) 

To create a union of two queries:

1. Select one of the queries, and then click **Filter**.
2. At the **Filter** tab, click **Union Query**.
3. EmpowerHR determines which eligible queries meet the required conditions (that is, have the same number of fields and corresponding data types), and displays a list of those queries.
4. Select the second query for the union query, and then click **Save**.
5. Click **OK** to run the union query. EmpowerHR:
    1. changes the colour of the **Union Query** button on the **Filter** tab to indicate a union query exists
    2. displays the query output in the query results window

| Next topic<br><br>[Use data alerts](/articles/ehr-user-guide/use-data-alerts) |
| --- |

© 2023 Fusion5. All rights reserved.