# Optimizing Table Row Comparison and Column Updates Using Flow Script

**URL:** <https://forum.novacura.com/t/optimizing-table-row-comparison-and-column-updates-using-flow-script/968>\
**Category:** Flow Connect\
**Created:** [June 13, 2025, 11:36am UTC](https://forum.novacura.com/t/optimizing-table-row-comparison-and-column-updates-using-flow-script/968 "2025-06-13T11:36:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![moiflk](https://avatars.discourse-cdn.com/v4/letter/m/7C9FD7/32.png) [@moiflk](https://forum.novacura.com/u/moiflk)\
**Post date:** [June 13, 2025, 11:36am UTC](https://forum.novacura.com/t/optimizing-table-row-comparison-and-column-updates-using-flow-script/968/1 "2025-06-13T11:36:18Z")

</div>

I have two tables as x and y and I want to identify the rows that are identical in both. For each matching row, I need to modify the value of one specific column, then display a combined table with only distinct rows, reflecting the changes. I can achieve this using nested loops, but I’m curious in knowing whether this can be done more efficiently using script modules.

**Tables :**  
let x = [{id:1, name:‘db’},  
{id:2, name:‘vsd’},  
{id:4, name:‘Henson’}]

let y = [{id:4, name:‘Henson’},  
{id:5, name:‘vsrb’}]

**Expected Results:**

let z = [{id:1, name:‘db’},  
{id:2, name:‘vsd’},  
**{id:4, name:‘UpdatedName’},**  
{id:5, name:‘vsrb’}]

---

<div class="post-metadata">

**Author:** ![ivstde](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.novacura.com/ivstde/32/146_2.png) [@ivstde](https://forum.novacura.com/u/ivstde)\
**Post date:** [June 13, 2025, 12:53pm UTC](https://forum.novacura.com/t/optimizing-table-row-comparison-and-column-updates-using-flow-script/968/2 "2025-06-13T12:53:07Z")

</div>

Hi,

(not sure if its the most performance optimal way but…) this should work:

 ![grafik](https://europe1.discourse-cdn.com/flex013/uploads/novacuratalk/original/1X/e343c0f4a18a6af3bcfe81fbf196958474c9e860.png)

Hope this helps!

B R  
Ivan

[Test.flow](https://forum.novacura.com/uploads/short-url/gPt7OAuvamkdbHJ5A3zacsPGkoC.flow) (187.8 KB)

---

<div class="post-metadata">

**Author:** ![fabianlidman](https://avatars.discourse-cdn.com/v4/letter/f/7C9FD7/32.png) [@fabianlidman](https://forum.novacura.com/u/fabianlidman)\
**Post date:** [June 13, 2025, 2:24pm UTC](https://forum.novacura.com/t/optimizing-table-row-comparison-and-column-updates-using-flow-script/968/3 "2025-06-13T14:24:04Z")

</div>

Hello!

I can think of a couple of ways. In this example, I’ve renamed the tables `xs` and `ys` (because i find it easier to think about it when the names are plural).

```auto

let xs = [
  {id:1, name:'db'},
  {id:2, name:'vsd'},
  {id:4, name:'Henson'}
]

let ys = [
  {id:4, name:'Henson'},
  {id:5, name:'vsrb'}
]

// METHOD 1: Select distinct
return select distinct
        r.id,
        (case when r in xs and r in ys then "UpdatedName" else r.name end) as name
       from (xs & ys) as r

// METHOD 2: Breaking it down into set-like operations

// Calculate the intersection of x and y
let intersection = xs as x where x in ys

// Calculate xs - ys and ys - xs (complement)
let xsMinusYs = xs as x where not (x in ys)
let ysMinusXs = ys as y where not (y in xs)

return xsMinusYs & ysMinusXs & (intersection with { name: "UpdateName" })

```

---

<div class="post-metadata">

**Author:** ![ivstde](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.novacura.com/ivstde/32/146_2.png) [@ivstde](https://forum.novacura.com/u/ivstde)\
**Post date:** [June 13, 2025, 2:38pm UTC](https://forum.novacura.com/t/optimizing-table-row-comparison-and-column-updates-using-flow-script/968/4 "2025-06-13T14:38:51Z")

</div>

Oh..my bad…didnt see this was for flow connect…nvm then (not there yet 🙂 )
