Skip to main content

Union

SQL

The Union gem lets you combine records from different tables for cases such as merging customer databases or aggregating logs from multiple servers.

Input and Output

PortDescription
in0The first input table.
in1The second input table.
inNOptional: Additional input tables.
outA single table containing all rows from input tables.

To add additional input ports, click + next to Ports.

All input tables must have identical schemas (matching column names and data types). If table columns have different orders or a different number of columns, use the UnionByName gem.

Parameters

ParameterDescription
Operation TypeShows that the set operation type is Union
Preserve duplicate rowsCheckbox to keep duplicates in the output table

Example

Let’s say you’re working with two tables: Table A and Table B.

  • Both tables contain order-related data.
  • Table A contains order information from customer 1, 2, and 3.
  • Table B contains order information from customer 1, 2, 3, and 4.
  • These tables contain some identical records (duplicates).

Table A

order_idcustomer_idorder_dateamount
10112024-12-01250.00
10222024-12-03150.00
10312025-01-15300.00
10432025-02-10200.00

Table B

order_idcustomer_idorder_dateamount
10312025-01-15300.00
10432025-02-10200.00
10542025-03-05400.00
10622025-03-07180.00

Result without duplicates

The following is the output table without duplicates.

order_idcustomer_idorder_dateamount
10112024-12-01250.00
10222024-12-03150.00
10312025-01-15300.00
10432025-02-10200.00
10542025-03-05400.00
10622025-03-07180.00

Result with duplicates

The following is the output table when you select Preserve duplicate rows in the gem configuration.

order_idcustomer_idorder_dateamount
10112024-12-01250.00
10222024-12-03150.00
10312025-01-15300.00
10432025-02-10200.00
10312025-01-15300.00
10432025-02-10200.00
10542025-03-05400.00
10622025-03-07180.00
tip

Order 103 and 104 are duplicate records.