We have MYSQL table of MERGE Storage Engine which merges data from 40 tables (“table01” through “table40“). Once we run a SELECT query we get all the entries from all the merged MySQL tables. The structure and behaviour of MERGE table is as expected.
However it happens that we need to identify which merged table row entry came from or corresponds to which merged table, i.e.
- rowA => “table01“
- rowB => “table12“
- rowC => “table12“
- rowD => “table35“
- rowE => “table39“
- row… => “table…“
Is there a way to do this with MySQL MERGE storage engine?
Not that elegant but you could add an identifying integer column on each of your tables, specify that column with a default value of 1 ,2 (depending on which table it is – you could even chuck in a lookup table (tableId –> tableName) and then you should be able to tell from which table a given row came.
You’d have to make the same changes to the MERGE table too of course…
Lovingly ripped off the MERGE MySQL docs:
You will have the rather dull task of altering all 40 tables though…