gpt4 book ai didi

php - Mysql查询忽略NULL和空字段

转载 作者:太空宇宙 更新时间:2023-11-03 11:10:09 31 4
gpt4 key购买 nike

我知道我有一个非常疯狂的查询,但是当我运行它时它会返回所有匹配项,无论字段 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,只是简单地留空,没有空格,只是空白

最佳答案

我认为 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 语句之一”

关于php - Mysql查询忽略NULL和空字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9184922/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com