In MySQL I want querying the information schema to find tables in a particular database.
I am using Regexp in the select statement like below.
select TABLE_NAME from information_schema.tables where TABLE_SCHEMA='testing' and TABLE_NAME REGEXP 'test|test_10'
Output:
123_test
123_test_10
temp_test
temp_test_10
Here I am getting list of tables which end with test and test_10 as indicated in the select statement.
I am getting the same result while using below.
select TABLE_NAME from information_schema.tables where TABLE_SCHEMA='testing' and TABLE_NAME REGEXP 'test'
Output:
123_test
123_test_10
temp_test
temp_test_10
Using the second statement how can I get only list of tables that end with 'test`.
The expected output I want is
Expected Output:
123_test
Also I would like to exclude some tables in the list. Like exclude the tables that start with temp and end with test
testnot specific to the end of the string. Thetest_10is redundant (per provided regex).TABLE_NAME REGEXP '(test|test_10)$'would be ending withtestortest_10.testandtempplaceholders or just literal values? I mean,LIKEis the best option if these are literal substrings.temp_testshould also be returned.test_10? it doesn't seem like you ever actually want that.