BookmarkSubscribeSubscribe to RSS Feed

join two tables different row numbers

Highlighted
Kevin

Occasional Contributor

Joined:

Jun 28, 2018

Hello,

 

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

 

The first table is 

TimeTool 
182 
182 
193 
193 

 

The 2nd table is 

TimeTool 
185 
198 
   
   

 

The final Table I want is

TimeTool 
185 
185 
198 
198
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson

Super User

Joined:

Jun 22, 2012

Solution

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",
	Add Rows( 4 ),
	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",
	Add Rows( 2 ),
	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 )
);

join.PNG

Jim
2 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

Solution

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",
	Add Rows( 4 ),
	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",
	Add Rows( 2 ),
	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 )
);

join.PNG

Jim
Kevin

Occasional Contributor

Joined:

Jun 28, 2018

Thank you, it works!