1

Lets say we have two tables in two sheets

sheet - NAME

Name id
Alex 1
Christine 2

sheet - AGE

id age
1 20
2 25

is there a way to get the following table in to a third sheet using appscripts without manually iterating through each row?

Name id age
Alex 1 20
Christine 2 25

I tried iterating through tables and joining, but the most of the parts of the app script code cannot be generalised to other scenarios.

sahanhe
  • 91
  • 5

2 Answers2

2

If the id is always aligned by row (as in the example data).

=query({query({Name!A1:B},"select Col1, Col2 where Col1 is not null"),query({Age!A1:B},"select Col1, Col2 where Col1 is not null")},"select Col1, Col2, Col4 where Col2 = Col3")


If the id is not aligned by row.

=FILTER({A1:A,B1:B, vlookup(B1:B,D1:E,2,0)},A1:A<>"")

h/t : @MaxMakhrov How to join tables using Query or Vlookup

Name

name

Age

age

Results

Results

Tedinoz
  • 5,911
  • 3
  • 25
  • 35
1

Alternate Solution

You could iterate through these tables using the JavaScript Array map() method like this:

function sampleJoinTables(array1,array2){
  var result = array1.map(x => array2.map(y => y[0] === x[1] ? [x[0],x[1],y[1]] : null).filter(z => z).flat());
  return result;
}

Sample

enter image description here

SputnikDrunk2
  • 3,398
  • 1
  • 5
  • 17