我知道我有一个非常疯狂的查询,但当我运行它时,它会返回所有匹配,而不管字段mvideo是否为空。
查询为:
SELECT *
FROM `weaponsprojects`
WHERE mvideo != ""
AND credit7 = "' .$person. '"
OR credit2 = "' .$person. '"
OR credit3 = "' .$person. '"
OR credit4 = "' .$person. '"
OR credit5 = "' .$person. '"
OR credit6 = "' .$person. '"
OR credit1 = "' .$person. '"
OR credit8 = "' .$person. '"
OR credit9 = "' .$person. '"
OR credit10 = "' .$person. '"
OR credit11 = "' .$person. '"
OR credit12 = "' .$person. '"
ORDER BY usort'并且当任一信用等于该人但它完全忽略mvideo部分时,它返回。这是为什么??
编辑:字段不为空,只是简单地清空,没有空格,只是空白
发布于 2012-02-08 06:32:19
我认为WHERE条件在逻辑上有缺陷...这里需要一些优先级,如下所示:
SELECT *
FROM `weaponsprojects`
WHERE mvideo != ""
AND (credit7 = "' .$person. '"
OR credit2 = "' .$person. '"
OR credit3 = "' .$person. '"
OR credit4 = "' .$person. '"
OR credit5 = "' .$person. '"
OR credit6 = "' .$person. '"
OR credit1 = "' .$person. '"
OR credit8 = "' .$person. '"
OR credit9 = "' .$person. '"
OR credit10 = "' .$person. '"
OR credit11 = "' .$person. '"
OR credit12 = "' .$person. '")
ORDER BY usort'通过添加(和),我们告诉WHERE语句:“mvideo不为空,并且它与OR语句之一相匹配。”
https://stackoverflow.com/questions/9184922
复制相似问题