Avatar of crafuse
crafuse
Flag for Canada

asked on 

Generate dynamic query based on changing table names

Experts -

VB.Net\MySQL

I have a group of tables in my db that have this naming convention:

Table123
Table124
Table125
Table126

A new table is added regularly, the next one will be Table127.

I need to query these tables as if they were one table, and currently i simply do this by hardcoding table names:

select * from Table123
union
select * from Table124
union
select * from table 125
union
select * from Table126;

my question is this: i would simply like to be able to get the list of table names (SELECT table_name FROM information_schema.tables WHERE table_name like 'Table1%'), and then iterate through the results to dynamically create the query above.

Best way to do this?

TIA,

crafuse
Visual Basic.NET

Avatar of undefined
Last Comment
Didier Vx

8/22/2022 - Mon