MySQL SELECT from a group of tables derived from INFORMATION_SCHEMA

Hey there. I have the following set of tables, which is variable and adds up every day:

data-2010-10-10
data-2010-10-11
data-2010-10-12
data-2010-10-13

Etc. All tables have the same structure, and I would like to select material from all tables at once. I cannot use the MERGE table since I am running InnoDB. In any case, I use the following statement to select table names from my information:

select table_name from `information_schema`.`tables` 
  where `table_schema` = 'mydb2' and `table_name` like 'data-%'

Which return all the tables that I would like to combine. I can also group_concat returned results to get a semicolon list as a separator. Now that I'm stuck, a selection query is executed that actually extracts data from these tables.

Any hints are welcome. Thank you ~ K

+3
1

SQL ( ) . information_schema , .

-, UNION :

SELECT ...
FROM (SELECT * FROM `data-2010-10-10`
      UNION ALL SELECT * FROM `data-2010-10-11`
      UNION ALL SELECT * FROM `data-2010-10-12`
      UNION ALL SELECT * FROM `data-2010-10-13`) AS u

. , , - , , , . antipattern Tribbles.

, , . , , , .


:

SQL ( ). , SQL-.

CONCAT(), PREPARE EXECUTE, . mysql- , , , script Python PHP - -.

+3

Source: https://habr.com/ru/post/1768883/


All Articles