xXxrk04
xXxrk04

Reputation: 195

MYSQL: LIKE with Except Condition

I need some help. I want to show database that has name "sample" but except "sample" with "fallback" word.

Database Name
  sample_1
  2_sample
  sample_fallback
  samsple_2
  s_sample
  fallback_sample

I just want to get:

sample_1
2_sample
samsple_2
s_sample

What should I add from this query?

  "SHOW DATABASES LIKE '%sample%';"

Upvotes: 0

Views: 867

Answers (2)

O. Jones
O. Jones

Reputation: 108651

You're going to need to query the information_schema directly to get this list.

select schema_name 
  from information_schema.schemata
 where schema_name like '%sample%'
   and schema_name not like '%fallback%'

SHOW DATABASES isn't flexible enough.

Upvotes: 1

Praveen Prasannan
Praveen Prasannan

Reputation: 7123

SHOW DATABASES LIKE '%sample%' AND NOT LIKE '%fallback%';

Upvotes: 0

Related Questions