MySQL 具有多个 LIKE 值的 SHOW TABLES 语句
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5609620/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SHOW TABLES statement with multiple LIKE values
提问by mysql_go
mysql> SHOW TABLES like 'cms'; +-------------------------+ | Tables_in_tianyan (cms) | +-------------------------+ | cms | +-------------------------+ 1 row in set (0.00 sec)
Result
结果
mysql> SHOW TABLES like 'cms' or like 'role'; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual...
How can I filter by multiple conditions ?
如何按多个条件过滤?
回答by Rich Adams
You need to use the WHERE
clause. As shown in the docs, you can only have a single pattern if you use "SHOW TABLES LIKE ..."
, but you can use an expression in the WHERE clause if you use "SHOW TABLES WHERE ..."
. Since you want an expression, you need to use the WHERE
clause.
您需要使用该WHERE
条款。如文档中所示,如果使用"SHOW TABLES LIKE ..."
,则只能有一个模式,但如果使用,则可以在 WHERE 子句中使用表达式"SHOW TABLES WHERE ..."
。既然你想要一个表达式,你就需要使用WHERE
子句。
SHOW TABLES
FROM `<yourdbname>`
WHERE
`Tables_in_<yourdbname>` LIKE '%cms%'
OR `Tables_in_<yourdbname>` LIKE '%role%';
回答by mikel
You can just use a normal SQL WHERE
statement to do it.
您可以使用普通的 SQLWHERE
语句来完成。
SHOW TABLES WHERE Tables_in_tianyan LIKE '%cms%'
回答by Edwin Dalorzo
show tables from mydb
where
Tables_in_mydb like '%statistics%'
or Tables_in_mydb like '%device%';
回答by Phoenix
You take table list using the below code
您使用以下代码获取表格列表
select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA = 'database_name'
Hope it will help you.
希望它会帮助你。