sql server - Should I use != or for not equal in T-SQL? - Stack Overflow
sql - Not equal != operator on NULL - Stack Overflow
query - Not equal to operator is not returning NULL values in SQL Server - Database Administrators Stack Exchange
mysql - SQL: How to perform string does not equal - Stack Overflow
Videos
Most databases support != (popular programming languages) and <> (ANSI).
Databases that support both != and <>:
Apache Derby 10.16:
!=and<>IBM Informix Dynamic Server 14.10:
!=and<>InterBase/Firebird:
!=and<>Microsoft SQL Server 2000/2005/2008/2012/2016:
!=and<>Mimer SQL 11.0:
!=and<>MySQL 8.0.33:
!=and<>Oracle 23c:
!=and<>PostgreSQL 15:
!=and<>Sybase Adaptive Server Enterprise 16.0:
!=and<>
Databases that support the ANSI standard operator, exclusively:
- IBM DB2 UDB 9.5:
<> - Microsoft Access 2010:
<>
Technically they function the same if you’re using SQL Server AKA T-SQL. If you're using it in stored procedures there is no performance reason to use one over the other. It then comes down to personal preference. I prefer to use <> as it is ANSI compliant.
You can find links to the various ANSI standards at...
http://en.wikipedia.org/wiki/SQL
<> is Standard SQL-92; != is its equivalent. Both evaluate for values, which NULL is not -- NULL is a placeholder to say there is the absence of a value.
Which is why you can only use IS NULL/IS NOT NULL as predicates for such situations.
This behavior is not specific to SQL Server. All standards-compliant SQL dialects work the same way.
Note: To compare if your value is not null, you use IS NOT NULL, while to compare with not null value, you use <> 'YOUR_VALUE'. I can't say if my value equals or not equals to NULL, but I can say if my value is NULL or NOT NULL. I can compare if my value is something other than NULL.
NULL has no value, and so cannot be compared using the scalar value operators.
In other words, no value can ever be equal to (or not equal to) NULL because NULL has no value.
Hence, SQL has special IS NULL and IS NOT NULL predicates for dealing with NULL.
Consider checking documentation:
NULL indicates that the value is unknown. A null value is different from an empty or zero value. No two null values are equal. Comparisons between two null values, or between a null value and any other value, return unknown because the value of each NULL is unknown.
If you consider that the value of istrue is unknown in the NULL case then it might or might not equal 1.
The expression istrue != 1 then evaluates to unknown
SQL only returns rows where the WHERE clause evaluates to true.
If you are on SQL Server 2022+ you can use
WHERE istrue IS DISTINCT FROM 1
To give the inequality semantics that you want (Fiddle).
Your where clause will return all rows where tester does not match username AND where tester is not null.
If you want to include NULLs, try:
where tester <> 'username' or tester is null
If you are looking for strings that do not contain the word "username" as a substring, then like can be used:
where tester not like '%username%'
Try the following query
select * from table
where NOT (tester = 'username')