我知道一个非常疯狂的查询,但是当我运行它时,它会返回所有匹配,无论字段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部分时它返回。这是为什么?
编辑:该字段不是NULL,只是简单地清空空格
答案 0 :(得分:4)
我认为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
个语句之一匹配“