Table "Observation" is filled with records, that come from table "Result" (observation_id = result_id)
In table "Observation" every record has a corresponding record that is also in the same table. Is there a way to link those two records, giving them their associated id. Tried a number of things but without any luck. Anyone care to take a look?
Current "Observation" table:
observation_id pk | related_observation_id |
---|---|
1 | |
8451 | |
2 | |
8452 | |
3 | |
8453 |
"Result" table:
result_id pk | value | linking_id |
---|---|---|
1 | 234 | 1 |
8745 | 231 | 1 |
2 | 653 | 2 |
8746 | 318 | 2 |
3 | 774 | 3 |
8747 | 321 | 3 |
Desired "Observation" table:
observation_id pk | related_observation_id |
---|---|
1 | 8745 |
8745 | 1 |
2 | 8746 |
8746 | 2 |
3 | 8747 |
8747 | 3 |
3
Answers
using self join and condition like this:
I believe this will do the update:
However some warnings…
Is it always 1:1, so two observations per linking id? If not, this will somewhat arbitrarily assign the value. If you have a preference, what would it be?
Alternatively, you can list all related observation ids, but you would need to change your datatype.