Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql search for segment of table name

I'm trying to select tables in a mysql database which have the same ending, e.g. staff_name, manager_name, customer_name (example). I was thinking of something along the lines of the following because it works if I have a definite table name.

SELECT * FROM "%_name";

I also tried this using a % instead of the _ with no luck. I'm not sure if there are other wildcards I could try. I've looked around, but none of the results seem to apply to parts of table names :/ Any suggestions?

like image 316
dgBP Avatar asked Aug 13 '12 09:08

dgBP


People also ask

How do I find the table name in MySQL?

The syntax to get all table names with the help of SELECT statement. mysql> use test; Database changed mysql> SELECT Table_name as TablesName from information_schema. tables where table_schema = 'test'; Output with the name of the three tables.

How do I find a specific field in MySQL?

How to list all tables that contain a specific column name in MySQL? You want to look for tables using the name of columns in them. SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA. COLUMNS WHERE COLUMN_NAME IN('column1', 'column2') AND TABLE_SCHEMA = 'schema_name';


2 Answers

SELECT TABLE_NAME 
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME like '%_name'
and TABLE_SCHEMA = 'your_db_name'

If you want to search for tables in your current DB you can do

SHOW TABLES LIKE '%_name'
like image 51
juergen d Avatar answered Oct 16 '22 00:10

juergen d


you can do in 3 way

show tables like '%yourtablename'
show tables like '%yourtablename%'

show tables like 'yourtablename%'
like image 43
Vipin Yadav Avatar answered Oct 15 '22 23:10

Vipin Yadav