Reputation: 1621
I created a query to get all table names with "prefix_"
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE 'prefix_%' AND TABLE_TYPE = 'BASE TABLE'
But in my database, I have tables with prefix_prefix_. How to avoid selecting them?
Upvotes: 2
Views: 2445
Reputation: 283
You can do this by just adding the exception to the where clause.
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE 'prefix_%' AND TABLE_NAME NOT LIKE 'prefix_prefix_%' AND TABLE_TYPE = 'BASE TABLE'
Upvotes: 5
Reputation: 37473
You can try using subquery and not like
select * from
(
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE 'prefix_%' and AND TABLE_TYPE = 'BASE TABLE'
)A where ABLE_NAME LIKE 'prefix_prefix_%'
Upvotes: 2