带多个LIKE值的SHOW TABLES语句 [英] SHOW TABLES statement with multiple LIKE values

查看:1887
本文介绍了带多个LIKE值的SHOW TABLES语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


mysql> SHOW TABLES like 'cms';
+-------------------------+
| Tables_in_tianyan (cms) |
+-------------------------+
| cms                     |
+-------------------------+
1 row in set (0.00 sec)

结果


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 ?

推荐答案

您需要使用WHERE子句.如 docs 所示,您只能拥有一个如果使用"SHOW TABLES LIKE ...",则使用单个模式,但是如果使用"SHOW TABLES WHERE ...",则可以在WHERE子句中使用表达式.由于需要表达式,因此需要使用WHERE子句.

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.

SHOW TABLES
FROM `<yourdbname>`
WHERE 
    `Tables_in_<yourdbname>` LIKE '%cms%'
    OR `Tables_in_<yourdbname>` LIKE '%role%';

这篇关于带多个LIKE值的SHOW TABLES语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆