Question

I have two tables with a similar structure in MySQL, one is the updated data and other is the history records for that data, and I need to perform analytics over all data we have there. I thought using a view that aggregates all data in one table would be useful but I'm not sure how to accomplish it.

Was it helpful?

Solution

Why not just create a view using UNION?

CREATE VIEW my_view AS
SELECT field1 AS f1, field2 AS f2 FROM table1
UNION
SELECT field1 AS f1, field2 AS f2 FROM table2

Then perform your analysis over that view.

More docs: UNION, CREATE VIEW.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top