使用MySQL匹配字符串的问题

时间:2011-06-24 00:40:01

标签: mysql sql

我在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 

有关我可能做错的任何建议吗?

2 个答案:

答案 0 :(得分:3)

将其更改为

ea.title LIKE '%tele%'

答案 1 :(得分:2)

我相信你想要LIKE

ea.title LIKE '%tele%'