I have very simple query like this:
SELECT * FROM `all_conversations` WHERE `deleted_1` != '1';
And my deleted_1
be default is null
or some user id, but for some reason this query always returns me 0 rows, i also tried <>
but still no luck what could be wrong?
EDTI So after running more querys i find out that my problems was default value of deleted_1
field, it was NULL
so i modified my query and now it works fine:
SELECT * FROM `all_conversations` WHERE `deleted_1` != 'NULL' AND `deleted_1` != 23
Here is the answer – Technically there is no difference between != and <>. Both of them work the same way and there is absolutely no difference in terms of performance or result.
The SQL Not Equal comparison operator (!=) is used to compare two expressions. For example, 15 != 17 comparison operation uses SQL Not Equal operator (!=) between two expressions 15 and 17.
<> means NOT EQUAL TO, != also means NOT EQUAL TO.
There is no != operator according to the ANSI/SQL 92 standard.
SELECT * FROM all_conversations WHERE deleted_1 <> 1 OR deleted_1 IS NULL
NULL values need special treatment: http://dev.mysql.com/doc/refman/5.1/en/working-with-null.html
I'd suggest using the diamond operator (<>
) in favor of !=
as the first one is valid SQL and the second one is a MySQL addition.
I recommend to use NULL-safe operator and negation
SELECT * FROM `all_conversations` WHERE NOT(`deleted_1` <=> '1');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With