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?
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 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';
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'
you can do in 3 way
show tables like '%yourtablename'
show tables like '%yourtablename%'
show tables like 'yourtablename%'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With