Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
How to find unmatched records from two tables.
With Mapping script prefix like this;
T1:
LOAD * Inline[
Shop Name, Qty
Store A,2
Store A,1
Store A,1
Store C,2
Store C,1
Store B,2
Store B,2];
T2:
LOAD *,
[Shop Name]&'_'&Qty as %Key,
[Shop Name]&'_'&Qty as TempField;
LOAD * Inline[
Shop Name, Qty
Store A,2
Store A,1
Store A,3
Store D,2
Store D,1
Store B,1
Store B,2
Store F,3
Store F,2
Store F,1
Store F,3];
MappingTable:
Mapping Load Distinct [Shop Name]&'_'&Qty as %Key,
[Shop Name]&'_'&Qty as TempField
Resident T1;
DROP Table T1;
FinalTable:
LOAD [Shop Name],
Qty,
ApplyMap('MappingTable',%Key,'Unmatched') as Flag
Resident T2
Where ApplyMap('MappingTable',%Key,'Unmatched')='Unmatched'; //Comment this line to display all records (Matched and Unmatched)
DROP Table T2;
DROP Field Flag From FinalTable;
EXIT SCRIPT;
filtering for "flag_ExistsIn_T1" = 1 will show records from t2 which exist in table1
filtering for "flag_ExistsIn_T2" = 1 will show records from t1 which exist in table2
table1_Temp:
LOAD *
,Shop&'-'&Qty as t1_Key
Inline[
Shop, Qty
Store A,2
Store A,1
Store A,1
Store C,2
Store C,1
Store B,2
Store B,2];
NOCONCATENATE
table2:
LOAD *
,Shop&'-'&Qty as t2_Key
, Exists(t1_Key,Shop&'-'&Qty)*-1 as flag_ExistsIn_T1
Inline[
Shop, Qty
Store A,2
Store A,1
Store A,3
Store D,2
Store D,1
Store B,1
Store B,2
Store F,3
Store F,2
Store F,1
Store F,3];
NOCONCATENATE
table1:
Load
Shop as t1.Shop
,Qty as t1.Qty
,t1_Key
,exists(t2_Key,t1_Key)*-1 as flag_ExistsIn_T2
Resident table1_Temp;
Drop table table1_Temp;