Choose Language Hide Translation Bar
Highlighted

Occasional Contributor

Joined:

Jun 28, 2018

## join two tables different row numbers

Hello,

I have a question of how to merge two tables with different row numbers.

The first table is

 Time Tool 18 2 18 2 19 3 19 3

The 2nd table is

 Time Tool 18 5 19 8

The final Table I want is

 Time Tool 18 5 18 5 19 8 19 8
1 ACCEPTED SOLUTION

Accepted Solutions

Super User

Joined:

Jun 22, 2012

Solution

## Re: join two tables different row numbers

Interactively, you would just run the Join platform

Tables==>Join

and specify to match based upon Time.

Below is a script doing the same thing as the interactive actions would do

``````Names Default To Here( 1 );
// Create the first table
dt1 = New Table( "Table 1",
New Column( "Time",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [18, 18, 19, 19] )
),
New Column( "Tool",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [2, 2, 3, 3] )
)
);
// Create the second data table
dt2 = New Table( "Untitled 10",
New Column( "Time",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [18, 19] )
),
New Column( "Tool",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [5, 8] )
)
);
// Join the 2 tables
dt3 = dt1 << Join(
With( dt2 ),
Merge Same Name Columns,
By Matching Columns( :Time = :Time ),
Drop multiples( 0, 0 ),
Include Nonmatches( 0, 0 ),
Preserve main table order( 1 )
);``````

Jim
2 REPLIES 2

Super User

Joined:

Jun 22, 2012

Solution

## Re: join two tables different row numbers

Interactively, you would just run the Join platform

Tables==>Join

and specify to match based upon Time.

Below is a script doing the same thing as the interactive actions would do

``````Names Default To Here( 1 );
// Create the first table
dt1 = New Table( "Table 1",
New Column( "Time",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [18, 18, 19, 19] )
),
New Column( "Tool",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [2, 2, 3, 3] )
)
);
// Create the second data table
dt2 = New Table( "Untitled 10",
New Column( "Time",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [18, 19] )
),
New Column( "Tool",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [5, 8] )
)
);
// Join the 2 tables
dt3 = dt1 << Join(
With( dt2 ),
Merge Same Name Columns,
By Matching Columns( :Time = :Time ),
Drop multiples( 0, 0 ),
Include Nonmatches( 0, 0 ),
Preserve main table order( 1 )
);``````

Jim

Occasional Contributor

Joined:

Jun 28, 2018

## Re: join two tables different row numbers

Thank you, it works!