如何使用SHOW TABLES检索表数据

时间:2015-02-25 22:23:54

标签: mysql

我的数据库中有5个表:

  

Torneio1,Torneio2,Torneio3,Torneio4,Toneio5。

它们都具有相同的结构。

id_position INT (primary key).
id_school int
name varchar
points int

我希望获得至少有一条记录id_school = 3

的所有表格

我已经尝试了

SHOW TABLES LIKE 'Torneio%' where id_school =3

但是我收到语法错误。

1 个答案:

答案 0 :(得分:1)

不确定我理解你想要什么输出,但如果要确定哪个表包含具有该特定值的行,则可以使用这个丑陋的联合解决方案:

select 'Torneio1' as tbl from Torneio1 where id_school = 3
union all
select 'Torneio2' as tbl from Torneio2 where id_school = 3
union all
select 'Torneio3' as tbl from Torneio3 where id_school = 3
union all
select 'Torneio4' as tbl from Torneio4 where id_school = 3
union all
select 'Torneio5' as tbl from Torneio5 where id_school = 3

这将打印匹配表的名称。