The field properties of multiple tables are all the same, how to write a script gracefully to concatenate the select results of all tables?

has N tables, indicating a string "table1","table2","table3"."tableN". The fields of these tables are all the same. Now take out the same fields from these N tables. How should sql write?
select field1,field2
from table1---tableN
this N represents dynamic change, what should I do? Thank you

There are so many

tables that you cannot write union one by one by hand

Jul.19,2022

union 

,
1-n  sql1 - sqln
,n ,

this requirement can be implemented in several ways, but which one to use depends on the usage scenario:

  1. the SQL of all tables is dynamically generated by defining union through database access frameworks such as MyBatis
  2. query the data of each table separately through the program, and then integrate
  3. in memory.
  4. define database stored procedures for processing (similar to method 2, but do not rely on other programs)

isn't it easy?

write a function to generate sql through scripting language


cannot be handwritten, so code generation

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b32a05-2b377.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b32a05-2b377.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?