# Matching unique identifiers for 2 columns

**URL:** <https://forum.knime.com/t/matching-unique-identifiers-for-2-columns/76534>\
**Category:** KNIME Analytics Platform\
**Created:** [January 12, 2024, 2:40pm UTC](https://forum.knime.com/t/matching-unique-identifiers-for-2-columns/76534 "2024-01-12T14:40:10Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![takbb](https://forum-cdn.knime.com/user_avatar/forum.knime.com/takbb/32/57077_2.png) [@takbb](https://forum.knime.com/u/takbb)\
**Post date:** [January 12, 2024, 6:15pm UTC](https://forum.knime.com/t/matching-unique-identifiers-for-2-columns/76534/3 "2024-01-12T18:15:18Z")

</div>

So … I had a chat with a friend… it went like this:

> If have a table of data consisting of UnitID and DeviceID
> 
> e.g.
> 
> Unit ID Device ID  
> 267.001.2 S1005215  
> 267.001.2 S1005216  
> 267.002.2 S1005215  
> 267.002.2 S1005216
> 
> what algorithm could I use to return the largest number of rows that does not contain a repeated Unit ID or Device ID

and my friend (ok, it was chatGPT) replied:

> “To find the largest number of rows that do not contain a repeated Unit ID or Device ID, you can use a graph-based approach. You can represent the relationships between Unit IDs and Device IDs as a graph and then find the largest set of rows that do not share common nodes (Unit ID or Device ID).”

It then presented me with some python, which I decided not to use because I wanted to find some non-python way, at least for now…

but what it did also say was this:

> This code creates a directed graph where each row in your data is represented as an edge between Unit ID and Device ID. It then finds the largest acyclic subgraph using the connected components of the undirected graph. Finally, it extracts the rows corresponding to the largest acyclic subgraph, which represents the largest number of rows that do not contain a repeated Unit ID or Device ID.

That seemed interesting, so I went searching for KNIME “acyclic subgraph”, which led me back to the “network” / “subgraph” nodes used here:

> [@KNIME version of an Alteryx tool - Make Group](https://forum.knime.com/t/knime-version-of-an-alteryx-tool-make-group/32380/5):
>
> @tobias.koetter That’s a great example of how the network nodes can be made to work! Hope this is OK, but I’ve taken your flow (now that you’ve done all the hard work, grin) and modified it a little. I’ve credited you and cited your original flow in this one. I removed all data from the input file that wasn’t “known” so effectively reduced it to just a list of relationships without strength or colour grouping information (i.e. “no prior knowledge”). I also added a few more relationships to se…

and here

> [@Building a hierarchy table from transactions](https://forum.knime.com/t/building-a-hierarchy-table-from-transactions/76114/5):
>
> Hi @Data_consumer , that’s looking good. If you are able to upload the workflow, I can take a look. My suggestion though would be that after the duplicate row filter , you establish the list of possible “top level” parents. You can do this by joining output from Duplicate Row filter (to itself), and joining on Investor = Investee, then keeping only the Left Unmatched entries. These are Investors that are not Investees and are therefore the set of “top level”. yes… That should give you a table c…

and that ultimately led me build a workflow that it would be good to try out with your data, because I have no idea if (or how!!) it works 😉 I suspect @tobias.koetter might be able to tell us! 🙂

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/3/0/30b30f8220fa7ec3278c7005f1361c5e0ad2f082.png)

What I can tell you is that given this input:

![image](https://forum-cdn.knime.com/uploads/default/original/3X/1/2/12a01fd0d5f0fb7577fa764b14d7bb8b9462604a.png)

it returns the following output (rows to keep)  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/2/2/22b8480b88a32d6bf49c52a1e1bf17d151fa6457.png)

and given this input:  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/3/e/3eb9c35d6e66e0a4819d8bab0204d69f281aac71.png)

it produces this output:  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/8/7/878ddee6b469cbfb6f14f78a26b78e6053659f14.png)

That appears right to me!

[remove duplication in two columns.knwf](https://forum.knime.com/uploads/short-url/kDozKwuozag0Kc78TCgBCXTpioF.knwf) (82.7 KB)

Will be good to know what happens with the “real” data.

btw Anybody interested in the python code that chatGPT generated for this can find the chat [here](https://chat.openai.com/share/ce895c63-5c23-4e62-bc43-dc466f44ff87)

---

_[View the full topic](https://forum.knime.com/t/matching-unique-identifiers-for-2-columns/76534)._
