我需要编写一个查询语句,如果我要求的所有表格都存在,将返回结果。我知道这是存在的:查询是否存在多个表格
show tables like 'user'
只是不知道如何扩展多表。我知道这是无效的代码,但类似
show tables like 'user' AND show tables like 'site' AND ...
谢谢!
我需要编写一个查询语句,如果我要求的所有表格都存在,将返回结果。我知道这是存在的:查询是否存在多个表格
show tables like 'user'
只是不知道如何扩展多表。我知道这是无效的代码,但类似
show tables like 'user' AND show tables like 'site' AND ...
谢谢!
select *
from information_schema.tables
where table_name in ('tb1','tb2','tb3')
and table_schema = 'your_db'
having count(table_name) = 3
嗯,我意识到有一个与该查询的问题。如果所有表存在,它只返回一条记录。这将是一个更好的解决方案
select group_concat(table_name order by table_name) as table_list
from information_schema.tables
where table_name in ('tb1','tb2','tb3')
and table_schema = 'your_db'
having count(*) = 3
可以使用INFORMATION_SCHEMA.TABLES对象 - 见http://dev.mysql.com/doc/refman/5.0/en/tables-table.html – dash 2012-01-09 23:01:12