2015-02-10 63 views
0

我需要一些幫助。我想顯示名稱爲"sample"的數據庫,但是除"sample""fallback"之外的字。MYSQL:喜歡與條件

Database Name 
    sample_1 
    2_sample 
    sample_fallback 
    samsple_2 
    s_sample 
    fallback_sample 

我只是想:

sample_1 
2_sample 
samsple_2 
s_sample 

要我從這個查詢添加什麼?

"SHOW DATABASES LIKE '%sample%';" 
+0

究竟是什麼問題?你沒有收回你期望的結果嗎? *你回來了什麼? – 2015-02-10 03:19:48

+1

你可以嘗試正則表達式引用此http://www.tech-recipes.com/rx/484/use-regular-expressions-in-mysql-select-statements/ – vijaykumar 2015-02-10 03:21:02

+0

@EricTaylor問題是,結果是 ** sample_1 2_sample sample_fallback samsple_2 s_sample fallback_sample ** 我只希望(無備用字) ** sample_1 2_sample samsple_2 s_sample ** 我應該怎麼對查詢添加序來獲取輸出 – xXxrk04 2015-02-10 03:23:34

回答

1

你會需要直接查詢information_schema得到這個列表。

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

SHOW DATABASES不夠靈活。

+0

謝謝先生。這是答案:) – xXxrk04 2015-02-10 03:58:40

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