2011-06-24 106 views
1

我在MySQL中匹配字符串時遇到問題。我有以下幾點:與MySQL匹配字符串的問題

SELECT ea.* 
FROM epf_application ea 
    JOIN epf_application_device_type ead ON ea.application_id = ead.application_id 
    JOIN epf_device_type edt ON ead.device_type_id = edt.device_type_id 
WHERE 
    edt.name = 'someDevice' 
LIMIT 30 

我想進一步過濾上述結果通過增加ea.title='%tele%'上述sql語句像下面

SELECT ea.* 
FROM epf_application ea 
    JOIN epf_application_device_type ead ON ea.application_id = ead.application_id 
    JOIN epf_device_type edt ON ead.device_type_id = edt.device_type_id 
WHERE 
    edt.name = 'someDevice' AND ea.title='%tele%' 
LIMIT 30 

上面的SQL語句不返回任何東西,然而,當我做了以下,我得到了一個結果。

SELECT ea.* 
FROM epf_application ea 
    JOIN epf_application_device_type ead ON ea.application_id = ead.application_id 
    JOIN epf_device_type edt ON ead.device_type_id = edt.device_type_id 
WHERE 
    edt.name = 'someDevice' AND ea.title='television' 
LIMIT 30 

關於我可能會做錯什麼的建議?

回答

3

將其更改爲

ea.title LIKE '%tele%' 
+0

我無法相信我錯過了。謝謝 – David

2

我相信你想LIKE

ea.title LIKE '%tele%'