Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SHOW TABLES statement with multiple LIKE values

 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 ?

like image 283
mysql_go Avatar asked Apr 10 '11 03:04

mysql_go


People also ask

How use LIKE operator in SQL for multiple values?

The SQL LIKE clause is used to compare a value to similar values using wildcard operators. There are two wildcards used in conjunction with the LIKE operator. The percent sign represents zero, one or multiple characters. The underscore represents a single number or character.

How do you select multiple values in a table?

To select multiple values, you can use where clause with OR and IN operator.

Can you have multiple froms in SQL?

With SQL, you can get information from columns in more than one table. This operation is called a join operation. In SQL, a join operation is specified by placing the names of those tables that you want to join in the same FROM clause of a SELECT statement.

How do I show tables in postgresql?

Use the \dt or \dt+ command in psql to show tables in a specific database.


2 Answers

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 image 110
Rich Adams Avatar answered Sep 18 '22 21:09

Rich Adams


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

SHOW TABLES WHERE Tables_in_tianyan LIKE '%cms%' 
like image 28
Michael Low Avatar answered Sep 19 '22 21:09

Michael Low