Skip to main content

UnionByName

Use the UnionByName gem to combine rows from multiple datasets by matching column names. This can help when working with data from different sources where schemas might vary slightly in order or structure, but the column names are consistent.

Input and Output

PortDescription
in0The first input table.
in1The second input table.
inNOptional: Additional input tables to include in the union.
outA single table containing the combined rows, with columns matched by name.

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

Parameters

ParameterDescription
Operation TypeChoose between two different operations.
  • Union By Name (No Missing Columns): All columns must be present in both tables.
  • Union By Name (Allow Missing Columns): Columns do not have to match between tables.

Example

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

  • Both tables contain order-related data.
  • Table B is missing the amount column that exists in Table A.
  • The columns in Table B that match Table A are ordered differently.

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_idorder_datecustomer_id
1032025-01-151
1042025-02-103
1052025-03-054
1062025-03-072

Result

The table below shows the output after running a UnionByName gem with Allow Missing Columns enabled.

Since Table B doesn’t have the amount column, Prophecy fills in null values for rows coming from Table B.

order_idcustomer_idorder_dateamount
10112024-12-01250.00
10222024-12-03150.00
10312025-01-15300.00
10432025-02-10200.00
10312025-01-15NULL
10432025-02-10NULL
10542025-03-05NULL
10622025-03-07NULL
caution

This example will fail if you select No Missing Columns in the gem settings, since Table B is missing a column in Table A.