具有多个 LIKE 值的 SHOW TABLES 语句

发布于 2024-10-31 12:55:36 字数 381 浏览 7 评论 0原文

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...

如何按多个条件进行过滤?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

风轻花落早 2024-11-07 12:55:36

您需要使用 WHERE 子句。如文档所示,您只能有一个如果您使用“SHOW TABLES LIKE ...”,则为单一模式,但如果您使用“SHOW TABLES WHERE ...”,则可以在WHERE子句中使用表达式。由于您需要一个表达式,因此需要使用 WHERE 子句。

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

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%';
心安伴我暖 2024-11-07 12:55:36

您可以使用普通的 SQL WHERE 语句来完成此操作。

SHOW TABLES WHERE Tables_in_tianyan LIKE '%cms%'

You can just use a normal SQL WHERE statement to do it.

SHOW TABLES WHERE Tables_in_tianyan LIKE '%cms%'
北渚 2024-11-07 12:55:36
show tables from mydb 
where 
  Tables_in_mydb like '%statistics%' 
  or Tables_in_mydb like '%device%';
show tables from mydb 
where 
  Tables_in_mydb like '%statistics%' 
  or Tables_in_mydb like '%device%';
把回忆走一遍 2024-11-07 12:55:36

您可以使用以下代码获取表格列表

select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA = 'database_name' 

You take table list using the below code

select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA = 'database_name' 
谢绝鈎搭 2024-11-07 12:55:36

这会有所帮助

SELECT 
TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME
 LIKE 'cms%';

this will help

SELECT 
TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME
 LIKE 'cms%';
稚气少女 2024-11-07 12:55:36
SHOW TABLES WHERE Tables_in_<yourdbname> REGEXP '^(regex-pattern1|regex-pattern2|...)
;
SHOW TABLES WHERE Tables_in_<yourdbname> REGEXP '^(regex-pattern1|regex-pattern2|...)
;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文