I have a mysql database that contains multiple tables with the same columns (not my design decision). These tables are named dynamically like codes_1, codes_2.... I would like to execute a query that will take the contents (rows) of codes_1, and codes_2..., and merge them together into one result.
I already have sql that can return the names of the tables using SCHEMA_INFORMATION.table_name, but I cannot figure out how to query each table based on the name, and how to merge the result of each table into one result.
So in reality here are the two questions:
how can I query multiple tables based on the table names that are returned as a query result?
how can I, after doing a select on each table, merge all the rows from the tables into one result?