我需要編寫一個查詢語句,如果我要求的所有表格都存在,將返回結果。我知道這是存在的:查詢是否存在多個表格
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