How do I select rows which don't equal a value and also include nulls in the returned data? I've tried:
SET ANSI_NULLS OFF SELECT TOP 30 FROM Mails WHERE assignedByTeam <> 'team01'
I want to return rows which don't have 'team01' in column assignedByTeam but I also want results containing nulls. Unfortunately, the above code doesn't work (doesn't return the nulls).
I'm using MS SQL Server 2008 Express.
In SQL null is not equal ( = ) to anything—not even to another null . According to the three-valued logic of SQL, the result of null = null is not true but unknown. SQL has the is [not] null predicate to test if a particular value is null .
<> 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.
We can use both SQL Not Equal operators <> and != to do inequality test between two expressions. Both operators give the same output.
Try checking for NULL explicitly:
SELECT TOP 30 col1, col2, ..., coln FROM Mails WHERE (assignedByTeam <> 'team01' OR assignedByTeam IS NULL)
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