Quantcast
Channel: Oracle, MySQL, Sybase, Informix and other databases
Viewing all articles
Browse latest Browse all 1350

SQL Query to union all table names on a database with MySQL

$
0
0

Hi,

I use this SQL query for find, in database MySql version 8.0.17, the tables whose name corresponds to the condition indicated in the clause LIKE

SELECT table_name FROM information_schema.TABLES WHERE table_name LIKE't#_contents#_s3%#_1#_2021'ESCAPE'#';+-------------------------+| TABLE_NAME              |+-------------------------+| t_contents_s300_1_2021  || t_contents_s34d_1_2021  || t_contents_s34g_1_2021  || t_contents_s3sv_1_2021  |+-------------------------+4rowsinset (0.30 sec)

My question is

How to do go about for union all these tables returned by the SQL query ?

Normally I would do this mode, but I don't know first all the names of the tables and the number of the tables returned by the SQL query... the names and the number of the tables it could be variable...

I'm not the administrator of this database. This schema is a remote hosting where I can only read..

SELECT
    `sUn`,
    `sUnName`,
    `contents` 'Set'FROM
    `t_contents_s300_1_2021` UNIONALLSELECT
    `sUn`,
    `sUnName`,
    `contents` 'Set'FROM
    `t_contents_s34d_1_2021` UNIONALLSELECT
    `sUn`,
    `sUnName`,
    `contents` 'Set'FROM
    `t_contents_s34g_1_2021` UNIONALLSELECT
    `sUn`,
    `sUnName`,
    `contents` 'Set'FROM
    `t_contents_s3sv_1_2021` ORDERBY
    `sUn` ASC;

Thanks in advance for any help.


Viewing all articles
Browse latest Browse all 1350

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>