whereIn
The whereIn
method returns a new table containing rows from the source table, where the rows match values in the filter table. The filter is updated whenever either table changes.
whereIn
is not appropriate for all situations. Its purpose is to enable more efficient filtering for an infrequently changing filter table.
Syntax
table.whereIn(rightTable, columnsToMatch...)
Parameters
Parameter | Type | Description |
---|---|---|
rightTable | Table | The table containing the set of values to filter on. |
columnsToMatch | String... | The columns to match between the two tables.
|
columnsToMatch | Collection | The columns to match between the two tables. |
Returns
A new table containing rows from the source table, where the rows match values in the filter table. The filter is updated whenever either table changes.
Examples
The following example creates a table containing only the colors present in the filter
table.
source = newTable(
stringCol("Letter", "A", "C", "F", "B", "E", "D", "A"),
intCol("Number", NULL_INT, 2, 1, NULL_INT, 4, 5, 3),
stringCol("Color", "red", "blue", "orange", "purple", "yellow", "pink", "blue"),
intCol("Code", 12, 13, 11, NULL_INT, 16, 14, NULL_INT),
)
filter = newTable(
stringCol("Colors", "blue", "red", "purple", "white")
)
result = source.whereIn(filter, "Color = Colors")
- source
- filter
- result
The following example creates a table containing only the colors and codes present in the filter
table. When using multiple matches, the resulting table will include only values that are in both matches. In this example, only one row matches both color AND codes. This results in a new table that has one matching value.
source = newTable(
stringCol("Letter", "A", "C", "F", "B", "E", "D", "A"),
intCol("Number", NULL_INT, 2, 1, NULL_INT, 4, 5, 3),
stringCol("Color", "red", "blue", "orange", "purple", "yellow", "pink", "blue"),
intCol("Code", 12, 13, 11, 10, 16, 14, NULL_INT),
)
filter = newTable(
stringCol("Colors", "blue", "red", "purple", "white"),
intCol("Codes", 10, 12, 14, 16)
)
result = source.whereIn(filter, "Color = Colors", "Code = Codes")
- source
- filter
- result