|
| 1 | +--- |
| 2 | +title: tJoin |
| 3 | +parent: Methods |
| 4 | +grand_parent: API |
| 5 | +nav_order: 31 |
| 6 | +--- |
| 7 | + |
| 8 | +# tJoin |
| 9 | +{: .d-inline-block } |
| 10 | + |
| 11 | +New |
| 12 | +{: .label .label-purple } |
| 13 | + |
| 14 | +Run a left, right outer or inner join on the provided data tables. |
| 15 | +{: .fs-4 .fw-300 } |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## Syntax |
| 20 | + |
| 21 | +*expression*.`tJoin`*(nType, leftTable, rightTable, Columns, matchKeys, \[predicate= vbNullString\], \[headers=True\])* |
| 22 | + |
| 23 | +### Parameters |
| 24 | + |
| 25 | +<table> |
| 26 | +<thead> |
| 27 | +<tr> |
| 28 | +<th style="text-align: left;">Part</th> |
| 29 | +<th style="text-align: left;">Description</th> |
| 30 | +</tr> |
| 31 | +</thead> |
| 32 | +<tbody> |
| 33 | +<tr> |
| 34 | +<td style="text-align: left;"><em>nType</em></td> |
| 35 | +<td style="text-align: left;">Required. Identifier specifying a <code>JoinType</code> enumeration variable representing the join nature.</td> |
| 36 | +</tr> |
| 37 | +<tr> |
| 38 | +<td style="text-align: left;"><em>leftTable</em></td> |
| 39 | +<td style="text-align: left;">Required. Identifier specifying a <code>CSVArrayList</code> Type object. Represents the first table in the join operation.</td> |
| 40 | +</tr> |
| 41 | +<tr> |
| 42 | +<td style="text-align: left;"><em>rightTable</em></td> |
| 43 | +<td style="text-align: left;">Required. Identifier specifying a <code>CSVArrayList</code> Type object. Represents the second table in the join operation.</td> |
| 44 | +</tr> |
| 45 | +<tr> |
| 46 | +<td style="text-align: left;"><em>Columns</em></td> |
| 47 | +<td style="text-align: left;">Required. Identifier specifying a <code>String</code> Type variable. Specifies the structure of the rows returned.</td> |
| 48 | +</tr> |
| 49 | +<tr> |
| 50 | +<td style="text-align: left;"><em>matchKeys</em></td> |
| 51 | +<td style="text-align: left;">Required. Identifier specifying a <code>String</code> Type variable. Represents the primary and preference keys to be matched.</td> |
| 52 | +</tr> |
| 53 | +<tr> |
| 54 | +<td style="text-align: left;"><em>predicate</em></td> |
| 55 | +<td style="text-align: left;">Required. Identifier specifying a <code>String</code> Type variable. Represents the condition that must be met when selecting rows.</td> |
| 56 | +</tr> |
| 57 | +<tr> |
| 58 | +<td style="text-align: left;"><em>headers</em></td> |
| 59 | +<td style="text-align: left;">Required. Identifier specifying a <code>Boolean</code> Type variable. Indicates if the tables have headers.</td> |
| 60 | +</tr> |
| 61 | +</tbody> |
| 62 | +</table> |
| 63 | + |
| 64 | +### Returns value |
| 65 | + |
| 66 | +*Type*: `CSVArrayList` |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +See also |
| 71 | +: [Filter method](https://ws-garcia.github.io/VBA-CSV-interface/api/methods/filter.html). |
| 72 | + |
| 73 | +## Behavior |
| 74 | + |
| 75 | +Use a string such as "{1-2,5,ID};{1-6}" as a predicate of the columns to indicate the join of columns 1 to 2, 5 and 'ID' of leftTable with the columns 1 to 6 of rightTable. Use a string such as "{*};{1-3}" to indicate the union of ALL columns of leftTable with columns 1 to 3 of rightTable. The predicate must use the dot syntax [t1.#][t1.fieldName] to indicate the fields of the table, where t1 refers to the leftTable. The matchKeys predicate must be given as "#/$;#/$". |
| 76 | + |
| 77 | +### ☕Example |
| 78 | + |
| 79 | +```vb |
| 80 | +Sub Join(ByRef lTable As CSVArrayList, ByRef rTable As CSVArrayList) |
| 81 | + Dim CSVint As CSVinterface |
| 82 | + |
| 83 | + Set CSVint = New CSVinterface |
| 84 | + With CSVint |
| 85 | + ' Performs a Left join returning the "1st" and "Country" fields of the left table and the |
| 86 | + ' "Total_Revenue" field of the right table, joined in the "Order_ID" field of both tables, |
| 87 | + ' of those records that satisfy the given condition. |
| 88 | + .tJoin JoinType.JT_LeftJoin _ |
| 89 | + lTable, rTable, _ |
| 90 | + "{1,Country};{Total_Revenue}", _ |
| 91 | + "Order_ID;Order_ID", _ |
| 92 | + "t2.Total_Revenue>3000000 & t1.Region='Central America and the Caribbean'" |
| 93 | + End With |
| 94 | + Set CSVint = Nothing |
| 95 | +End Sub |
| 96 | +``` |
| 97 | + |
| 98 | +[Back to Methods overview](https://ws-garcia.github.io/VBA-CSV-interface/api/methods/) |
0 commit comments