<@UNION>
Syntax
<@UNION ARRAY1=arrayVarName1
ARRAY2=arrayVarName2 [COLS=compCol
[compType]] [SCOPE1=scope1]
[SCOPE2=scope2]>
Description
Returns the union of two arrays. The union
consists of the combination of both arrays, with duplicates removed.
Duplicates are found based on the values of the specified columns,
checked using the specified comparison type.
The two input arrays are not modified. To
store the result of this meta tag in a variable, use a variable
assignment.
Note:
To join two arrays without
removing duplicates, use the <@ADDROWS> tag.
The ARRAY1 and ARRAY2
attributes specify the names of variables containing arrays. The
arrays must contain the same number of columns. The optional COLS
attribute specifies the column(s) to consider when eliminating
duplicates: the columns are specified using column numbers or names,
with an optional comparison type (compType). The arrays must
have the same number of columns; otherwise, an error is generated.
Valid comparison types are SMART
(the default), DICT, ALPHA and NUM.
DICT compares columns alphabetically, irrespective of case.
ALPHA performs a case-sensitive comparison. NUM
compares columns numerically. SMART checks whether values
are numeric or alphabetic and performs a NUM or DICT
comparison.
If no COLS attribute is
specified, the elimination of duplicates is accomplished via a SMART
comparison type that examines all columns in a row.
The SCOPE1 and SCOPE2
attributes specify the scope of the variables specified by ARRAY1
and ARRAY2, respectively. If the attribute is not specified,
the default scoping rules are used.
Meta tags are permitted in any of the
attributes.
Examples
- If the variable old_items
contains the following array:
and the array new_items
contains the following:
<@UNION ARRAY1="old_items"
ARRAY2="new_items"> returns:
- If the variable test contains
the following array:
and the variable test2
contains:
1 |
a |
a |
2 |
b |
b |
3 |
c |
c |
3.0 |
c |
c |
<@UNION ARRAY1="test"
ARRAY2="test2"> returns:
- Variable usr1 contains the
following:
Gilbert |
Steve |
1823-1344 |
$433.00 |
Brown |
Robert |
5543-1233 |
$332.50 |
Brown |
Marsha |
1122-5778 |
$541.00 |
Variable usr2 contains the
following:
Kelly |
Herbert |
5543-1443 |
$100.50 |
Brown |
Robert |
6670-1123 |
$1123.75 |
MacDonald |
Bill |
1551-0787 |
$150.75 |
To find the unique users in both
arrays, you would find the union of the two arrays based on the
first two columns.
<@UNION ARRAY1="usr1"
ARRAY2="usr2" COLS="1, 2"> returns:
Gilbert |
Steve |
1823-1344 |
$433.00 |
Brown |
Robert |
6670-1123 |
$1123.75 * |
Brown |
Marsha |
1122-5778 |
$541.00 |
Kelly |
Herbert |
5543-1443 |
$100.50 |
MacDonald |
Bill |
1551-0787 |
$150.75 |
* Tango returns just one of the rows that have the
same values in the specified columns (1 and 2).
The values in columns 3 and 4 are
ignored for the purpose of the union operation since COLS="1,
2" is specified.
See Also
<@ADDROWS>
<@DISTINCT>
<@FILTER>
<@INTERSECT>
<@SORT>
|