MySQL – How to Check If Several Tables Exist and Show Results

MySQLtable

I would like to check if several tables exist in a database, and return a easy to understand return, I know you can check if a single table exists by running

show tables like "foo";

but is there something that could check more than one, and could return something that is not a list of tables that exists since there are more than a dozen that needs to be checked.

Perhaps counting the found tables?

Best Answer

Perhaps this is better solution for you:

SELECT COUNT(*) AS tables_found_count
FROM `information_schema`.`tables` 
WHERE `TABLE_SCHEMA` = 'database_name' AND
`TABLE_NAME` IN ('table1', 'table2')

It returns the count of found tables. Please list the tables in brackets and specify your database name instead of database_name.