Skip to main content

Intersect

SQL

Use the Intersect Gem to return only the rows that appear in all input tables. This is useful for identifying overlapping data, such as customers who are active on multiple platforms, or transactions that appear across different systems or logs.

Input and Output

PortDescription
in0The first input table to compare.
in1The second input table to compare.
inNOptional: Additional tables to compare.
outA single table containing only rows that appear in all input tables.

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

All input tables must have identical schemas (matching column names and data types).

Parameters

ParameterDescription
Operation TypeShows that the set operation type is Intersect
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.
  • Tables A and B each contain some identical records (duplicates).

Table A

order_idcustomer_idorder_dateamount
10112024-12-01250.00
10222024-12-03150.00
10112024-12-01250.00
10432025-02-10200.00

Table B

order_idcustomer_idorder_dateamount
10112024-12-01250.00
10432025-02-10200.00
10542025-03-05400.00
10622025-03-07180.00
10112024-12-01250.00

Result

Default

The table that results from the Intersect gem only includes the records present in all the input tables.

order_idcustomer_idorder_dateamount
10112024-12-01250.00
10432025-02-10200.00

The output indicates that order 101 and 104 appear in both Table A and Table B. By default, the duplicate row for order 101 is removed from the output.

Preserve duplicates

If the preserve duplicates option is selected, the duplicates present in all inputs are preserved.

order_idcustomer_idorder_dateamount
10112024-12-01250.00
10112024-12-01250.00
10432025-02-10200.00

The output is the same as above, except the duplicate order 101 is retained.