I have the following problem to solve:
Let's say there is a table A that contains an number of elements, this table is copied to become table B. In table B some of the original elements are lost and some are added. A reference table AB keeps track of these changes. Then table B is copied to be table C and again some of the existing elements get lost and some are added. Another reference Table BC keeps track of these relations. ... etc.
There is an n number of such tables with an n-1 number of reference tables.
If I want to know which of the elements of my choice in table C where already present in A, I can do that by doing something like:
SELECT AB.oldID
FROM AB
JOIN BC
WHERE BC.newID IN (x, y, z)
Now since the number of reference tables can wary, the number of JOIN lines can wary.
Should I concatenate the query by looping over the steps and adding JOIN lines or shoudl I rather write a recursive function that selects only the members of the next step and then let the function call itself until I have the end result?
Or is there an other even better way to do something like that?