Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I have the following two tables,
table1:
a | b | c | d |
---|---|---|---|
1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 |
11 | 22 | 33 | 44 |
55 | 66 | 77 | 88 |
1 | 1 | 1 | 1 |
2 | 2 | 2 | 2 |
3 | 3 | 3 | 3 |
4 | 4 | 4 | 4 |
5 | 5 | 5 | 5 |
table2:
i | j | k | l |
---|---|---|---|
4 | 3 | 2 | 1 |
9 | 8 | 7 | 6 |
99 | 88 | 77 | 66 |
55 | 44 | 33 | 22 |
1 | 1 | 1 | 1 |
2 | 2 | 2 | 2 |
9 | 9 | 9 | 9 |
8 | 8 | 8 | 8 |
7 | 7 | 7 | 7 |
What I want to do is to match the content of table1 with the content of table2. If the content of table2 exists in table1, it is deleted in table1, and if it does not exist, the content of table2 is inserted into table1.
Thanks a lot!
Hi junzai,
You can use AutoNumberHash128 and Exists functions to check if the row occurs in both table.
Script:
Table1:
Load *,AutoNumberHash128(A,B,C,D) as RowKey1 inline [
"A","B","C","D"
1,2,3,4
5,6,7,8
11,22,33,44
55,66,77,88
1,1,1,1
2,2,2,2
3,3,3,3
4,4,4,4
5,5,5,5
];
Table2:
Load *,AutoNumberHash128(I, J, K, L) as RowKey2 inline [
"I","J","K","L"
4,3,2,1
9,8,7,6
99,88,77,66
55,44,33,22
1,1,1,1
2,2,2,2
9,9,9,9
8,8,8,8
7,7,7,7
];
Master:
LOAD A,B,C,D Resident Table1
WHERE NOT Exists(RowKey2,RowKey1);
Concatenate
LOAD I AS A, J AS B, K AS C, L AS D Resident Table2
WHERE NOT Exists(RowKey1,RowKey2);
DROP TABLES Table1,Table2;
Output: