MySQL不等于不工作 [英] MySQL not equals to isn't working

查看:53
本文介绍了MySQL不等于不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

$query = mysql_query("SELECT P_Id, Thing,Something Date
    FROM priv
    WHERE Something = '$thing' AND thing2 <> 'This'
    LIMIT 1"
) or die(mysql_error());

代码在没有 "thing2 <> 'this'" 语句的情况下正常工作,但是当我实现 "thing2 <> 'this'" 时,它返回 0 结果.好像表中没有空行,但是表的thing2行中有空(NULL)行.

Code is working properly without "thing2 <> 'this'" statement, but when I implement "thing2 <> 'this'", it returns 0 result. As if there were no empty rows in the table, but there are empty (NULL) rows in the thing2 row of the table.

问题是,这个不等于"语句不起作用,我已经尝试了所有方法,但它不会返回任何值.

The problem is, that this "not equals" statement is not working, and I've tried everything, but it won't return any values with it.

编辑(解释词):列看起来像这样 - P_Id |东西|日期 |事情 1 |事情 2 和我需要从某行接收 P_Id,其中某物 = 某物 AND Thing1 不是 EQLAS 到这个"(上例)和 Thing2 也不等于这个".我知道这听起来很疯狂.对不起

edit(word of explanation): Columns looks like this - P_Id | Something | Date | Thing1 | Thing 2 and i need to receive P_Id from a row where Something = Something AND Thing1 NOT EQLAS to 'this'(above example) and Thing2 ALSO NOT EQUALS to 'this'.I know it sounds crazy.Sorry

好的,所以我尝试了一些实验,结果表明thing2 <>"thingy 不适用于things1/thing2 列,但其他列(例如Something"表中的this"条目也可以正常工作)(找到没有这个"条目的 nerest 行).但是为什么这对 things1 和 2 不起作用?我试过重命名 things 列,但没有结果.

Ok, so i have tried some experiments, and it apears that "thing2 <>" thingy is not working on things1/thing2 columns, but other columns like "Something" table where are also 'this' entries it works properly(finding nerest row where there is not 'this' entry).But why this isn't working with things1 and 2???i have tried rename things column, but no result.

推荐答案

something <>NULL 将评估为 NULL.如果在查询中使用与 0(或 false)几乎相同.

something <> NULL will evaluate to NULL. And if used in a query that's pretty much the same as 0 (or false).

请记住,SQL 使用三值逻辑,而不是简单的二进制逻辑.

Remember that SQL uses three-valued logic and not simple binary logic.

您可能需要使用 IS NULL 显式检查 NULL:

You might need to check for NULL explicitly using IS NULL:

... OR THING IS NULL

或者,您可以使用 NULL-安全等于运算符 <=> 带否定(这是 MySQL 特定的,但是,它不是标准的 SQL):

Alernatively you can use the NULL-safe equals operator <=> with a negation (this is MySQL specific, however, it's not standard SQL):

... AND NOT (THING <=> 'This')

这篇关于MySQL不等于不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆