Query a database with results from multiple tables?

后端 未结 2 1993
無奈伤痛
無奈伤痛 2020-12-22 02:08

There are some similar questions around but they aren\'t quite what I\'m looking for, so forgive me if you think this is answered elsewhere.

I am basically looking

2条回答
  •  北海茫月
    2020-12-22 02:40

    I would suggest generating the SQL statement.

    Try doing:

    select concat('select * from ', table_name) as query
    from Information_Schema.tables
    where table_schema =  and
          table_name like 
    

    You can then run this as a bunch of queries by copying into a query editor window.

    If you want everything as one query, then do:

    select concat('select * from ', table_name, ' union all ') as query
    from Information_Schema.tables
    where table_schema =  and
          table_name like 
    

    And remove the final "union all".

    This has the table name matching a like. Leave out the table_name part of the WHERE to get all tables. Or, include specific tables using table_name in ().

提交回复
热议问题