This should do it:
DT1 = New Table("DT1",
<< Add Rows(3),
<< New Column("Name", character, Values({"Adam","Bob","Chris"})),
<< New Column("Section", character, Values({"A","A","B"})),
<< New Column("Subject", character, Values({"Math","Science","English"}))
);
DT2 = New Table("DT2",
<< Add Rows(3),
<< New Column("Name", character, Values({"Adam","Bob","Chris"})),
<< New Column("Section", character, Values({"A","A","B"})),
<< New Column("Score", numeric,continous, Values({80,90,84}))
);
LSTcols1 = DT1 << Get Column Names(string);
LSTcols2 = DT2 << Get Column Names(string);
STRjoinCols = "";
For(LVC=1,LVC<=N Items(LSTcols1),LVC++,
STRcol = LSTcols1[LVC];
If(
Contains(LSTCols2,STRcol)
,
If(
STRjoinCols == ""
,
STRjoinCols = ":"||STRcol||"==:"||STRcol
,
STRjoinCols = STRjoinCols||", :"||STRcol||"==:"||STRcol
);
);
);
expr = Eval Insert(
"\[
DT3 = DT1 << Join(
With( DT2 ),
Merge Same Name Columns,
Match Flag( 0 ),
By Matching Columns( ^STRjoinCols^ ),
Drop multiples( 0, 0 ),
Include Nonmatches( 0, 0 ),
Preserve main table order( 0 ),
Output Table( "DT3" )
);
]\"
);
Eval( Parse( expr ) );