i have a table with 12 columns:
table1:
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| abc | 1 | 000 | aaa | zzz | 2 | 234 | OOO | 00001 | 01 | 123 | 214 |
| def | 2 | 023 | bbb | yyy | 4 | 345 | PPP | 00002 | 02 | 133 | 224 |
| ghi | 3 | 011 | ccc | xxx | 6 | 456 | QQQ | 00003 | 03 | 143 | 234 |
| jkl | 4 | 112 | ddd | www | 8 | 567 | RRR | 00004 | 04 | 153 | 244 |
i would like to use 3rd column data in a loop and fetch 'best match' data from another table.
table2:
| 1 | 2 | 3 | 4 |
|---|---|---|---|
| 0 | 777 | 676 | america |
| 00 | 888 | 878 | england |
| 01 | 999 | 989 | france |
| 02 | 666 | 656 | germany |
3rd column data will be trimmed in the loop until a match in table2 is fetched.
first row:
iter 1: table1 row1 col3=000 -- no match in table
iter 2: table1 row1 col3=00 -- return england, replace table1 row1 col12=214 with 'england'
updated row: abc,1,000,aaa,zzz,2,234,OOO,00001,01,123,england
second row:
iter 1: table1 row2 col3=023 -- no match in table
iter 2: table1 row2 col3=02 -- return germany, replace table1 row1 col12=224 with 'germany'
updated row: def,2,023,bbb,yyy,4,345,PPP,00002,02,133,germany