I have a MYSQL db with following data
col1 col2
1234 7056854
6854 2261335
1335 2018999
8999 28128121
9000 80028128
From the above, I have to read first record and get col2 and get last 4 digits from col2 and again search in table with 6854 in col1 and get the col2 . Again take last 4 digits of col2 of corresponding col1 and search in table. and so on. So finally output should be in a linked list like
1234-7056854-2261335-2018999-28128121.
Note : From the above output we don't have 80028128 because 8121 is not in col1.
Please suggest me the algorithm.