I have two tables.
table1:
id | array1
1 | ['a', 'b', 'c']
2 | ['b', 'a', 'c']
3 | ['c', 'b', 'a']
table2:
id | value2
1 | 'b'
3 | 'a'
I wish to get the following table:
id | value3
1 | 'c'
2 | 'b'
3 | 'c'
Explanation: what I want is that if the id in table1 does't exist in table2, then return the first element of array1. if the id in table1 exists in table2, then return the next element of value2 in array1 (in this case if value2 is the last element in array1, return the first element of array1)
How can I achieve this goal?