Table1: tb1
|ID|Reference|
|1|ABCD|
|2|EFGH|
|3|IJKL|
|4|MNOP|
|5|MNOP|
Table2: tb2
|Reference |UpdatedID |
|ABCD | |
|ABCD | |
|EFGH | |
|EFGH | |
|EFGH | |
|EFGH | |
|IJKL | |
|MNOP | |
|MNOP | |
I need to update an empty column of Table tb2
on the basis of tb1
.
The common column to join is the Reference
column of both tables where ID of tb1
will be updated to the UpdatedID
column of the tb1
table.
After applying the join column the record is getting increased as in tb1
table the same Reference
has a different ID which needs to be updated same in tb2
table.
How I am supposed to proceed.
JOIN query used:
select
A.csvRefNumber,
A.reference,
B.reference
from
tb1 A
left join
tb2 B on A.Reference = B.Reference
order by
csvRefNumber
Required output:
|Reference |UpdatedID |
|ABCD |1 |
|ABCD |1 |
|EFGH |2 |
|EFGH |2 |
|EFGH |2 |
|EFGH |2 |
|IJKL |3 |
|MNOP |4 |
|MNOP |5 |