Select Rows that match values in another column

Hi everyone!

I need to select Rows in Column1 depending on what is present in another column, for example Column2, but not necessarily the same row.

Something like this

     Column 1 Column2

Row1 A No
Row2 A A
Row3 B B
Row4 X No
Row5 Y Y

If value in Column 2 is present in Column 1 then I must select this row. In this case I would select Row1, Row2, Row3, Row5.

With Python I would just create a list of what is present in Column 2 and iterate over the elements present in that list and select the rows in Column1 that match those elements. However in Knime I really do not know how to do it…

Thanks so much in advance!

There are probably several ways to approach this.

If you can do it in Python, then one idea is to use a Python Script node to accomplish the task in KNIME.

Alternatively, you can use a Table Row to Variable Loop Start node followed by a Row Filter node to grab each value in column 2 in turn, and filter out rows where the values in column 1 do not match. This is a screenshot of the workflow:

This is the starting data:

This is the output:

1 Like

Another approach could be this:
where you groupby column2 to grab the distinct values and use them to filter column1 in the original table.



Hello there,

@elsamuel think your solution can have duplicate rows in case there are multiple referenced values in column2 so would avoid it. Plus in case of big tables loop is always slower than loopless solution.

@Luca_Italy you can avoid GroupBy node and only use Reference Row Filter as it doesn’t require distinct value list :wink:



Yeah, you are right :slight_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.