当有一些时,MySQL显示零结果?

时间:2014-08-06 12:49:37

标签: mysql

我有一张表格如下:

id | description | db_url | form_url | user | projectid

2 | nailbar | TSF/nailbar/index.php | TSF/nailbar/upload.php | test_user | 2

1 | jewellery | TSF/jewellery/index.php | TSF/jewellery/upload.php | test_user | 1

1 | jewellery | TSF/jewellery/index.php | TSF/jewellery/upload.php | test_user2 | 1

3 | locker | TSF/locker/index.php | TSF/locker/upload.php | test_user | 3

当我执行以下查询时,没有任何内容出现:

SELECT * 
FROM projects
JOIN member_projects ON member_projects.projectid = projects.id
WHERE user =  'test_user'
AND db_url =  'TSF/locker/index.php'
LIMIT 0 , 30

显然有匹配,所以我无法理解为什么会出现零结果?

1 个答案:

答案 0 :(得分:1)

当字符串的开头或结尾有多余的字符时,通常会发生这种情况。最可能的罪魁祸首是网址。你可以尝试:

SELECT * 
FROM projects p JOIN
     member_projects mp
     ON mp.projectid = p.id
WHERE user =  'test_user' AND
      trim(db_url) =  'TSF/locker/index.php'
LIMIT 0 , 30;

您还可以查找"包含"而不是完全匹配,如果以上不起作用:

SELECT * 
FROM projects p JOIN
     member_projects mp
     ON mp.projectid = p.id
WHERE user =  'test_user' AND
      db_url like '%TSF/locker/index.php%'
LIMIT 0 , 30;