mysql - Concatenate JOINS or write recursive function - problem with dynamic number of JOIN queries -


i have following problem solve:

let's there table contains number of elements, table copied become table b. in table b of original elements lost , added. reference table ab keeps track of these changes. table b copied table c , again of existing elements lost , added. reference table bc keeps track of these relations. ... etc.

there n number of such tables n-1 number of reference tables.

if want know of elements of choice in table c present in a, can doing like:

select ab.oldid ab join bc bc.newid in (x, y, z) 

now since number of reference tables can wary, number of join lines can wary.

should concatenate query looping on steps , adding join lines or shoudl rather write recursive function selects members of next step , let function call until have end result?

or there other better way that?

since table names vary, you'll need build kind of dynamical query.

if recursive function approach, you'll need pass resultsets between function calls somehow.

mysql has no array datatype, , storing results in temp table way long.

conclusion: use joins.

update:

here's sample query returns entries persisted through revision a revision m (with 1 table design):

select  *    entries e   not exists         (         select  *            revisions r         join    revision_changes rc         on      rc.revision_id = r.id           rc.entry_id = e.id                 , rc.deleted                 , r.revision_id between 'a' , 'm'         ) 

this way, fill added , deleted fields of revision_changes revisions entry added or deleted.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -