I have two tables as below.
I want to update table_a.fid to table_b.id when table_a.name=table_b.name and table_a.value=table_b.value and table_b.id is not set to other table_a.fid
table_a (a):
id(int) name(varchar) value(varchar) fid(int)
1 name_a value_1 0
2 name_a value_1 0
3 name_a value_1 0
4 name_b value_2 0
5 name_c value_3 0
table_b (b):
id(int) name(varchar) value(varchar)
1 name_a value_1
2 name_a value_1
3 name_b value_2
4 name_b value_2
table_a expected results:
id name value fid
1 name_a value_1 1 // b.id(1,2) matched, so set the first b.id(1) to a.fid(1)
2 name_a value_1 2 // b.id(1,2) matched and b.id(1) already set to a.fid(1), so set the second b.id(2) to a.fid(2)
3 name_a value_1 0 // b.id(1,2) matched and b.id(1,2) already set to a.fid(1,2), so is 0
4 name_b value_2 3 // b.id(3,4) matched. so set the first b.id(3) to a.fid
5 name_c value_3 0 // b not matched