|
OriginalGriff wrote: Dali-esque Surrealistic? or womenizer?
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Nelek wrote: womenizer? My experience is that SQL lacks, er, discrimination in who it molests.
Software Zen: delete this;
|
|
|
|
|
...except there's an "or" in there: logically, it shouldn't matter: if it's null, at least one of the conditions is true.
I have a feeling that "null=string" evaluates to null, and then "field is null" evaluates to Boolean, then "boolean or null" evaluates to null, which is why it doesn't work. But that's somewhat abstruse.
Which server is this: is it SQL Server or MySQL... or perhaps something else?
|
|
|
|
|
But the IS NULL check is made on TableTwo.TableTwoID
While string compare is made with TableTwo.StringColumn
So I see no incorrect handling, but of course it is not very intuitiv.
modified 19-Jan-21 21:04pm.
|
|
|
|
|
Yeah - you're right. Hadn't had coffee yet. LOL!
|
|
|
|
|
modified 19-Jan-21 21:04pm.
|
|
|
|
|
Dan Sutton wrote: I have a feeling that "null=string" evaluates to null, and then "field is null" evaluates to Boolean, then "boolean or null" evaluates to null, which is why it doesn't work.
Pretty much, but it depends on the operator and the boolean value. If it's possible to short-circuit the operator, it doesn't matter if one condition is Null .
AND | True | False | Null
----------------------------
True | True | False | Null
False | False | False | False
Null | Null | False | Null
OR | True | False | Null
----------------------------
True | True | True | True
False | True | False | Null
Null | True | Null | Null
It's sometimes easier to think of Null as "unknown".
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I know: I failed to see first time around that the comparisons were made on separate columns. Coffee. It's a mandatory component first thing in the morning. Of course, not having had any, I failed to realise that, too!
|
|
|
|
|
Exactly - in Codd's original work (which defined Relational Database Management Systems), this is referred to as null progagation.
Interesting, in The Relational Model for Database Management Systems V2, he introduced two null values one indicates the value is unknown and inapplicable (like the null behaviour you described), and the other indicating the value is unknown and applicable (which would give the behaviour Chris was expecting).
Sadly, to the best of my knowledge, no-one bothered pursuing any of the good ideas in there.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
It's simple three-valued Boolean logic - what's the problem?!
Chris Maunder wrote: IsNull(TableTwo.StringColumn, '') <> 'value'
Except that's not SARGabale.
WHERE
TableTwo.StringColumn Is Null
Or
TableTwo.StringColumn != 'value'
(You can remove TableTwo.TableTwoID Is Null , because if that's true, TableTwo.StringColumn will also be Null .)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: It's simple three-valued Boolean logic
True, False, and Surprise.
cheers
Chris Maunder
|
|
|
|
|
True, False, and FileNotFound.
What Is Truth? - The Daily WTF[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
And avoid "!=" in SQL
modified 19-Jan-21 21:04pm.
|
|
|
|
|
Only if you're anal about standards-compliance.
Databases that support both != and <> :
- MySQL 5.1
- PostgreSQL 8.3
- SQLite
- Oracle 10g
- Microsoft SQL Server 2000/2005/2008/2012/2016
- IBM Informix Dynamic Server 10
- InterBase/Firebird
- Apache Derby 10.6
- Sybase Adaptive Server Enterprise 11.0
Databases that support the ANSI standard operator, exclusively:
- IBM DB2 UDB 9.5
- Microsoft Access 2010
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
0x01AA wrote: BTW: Have some Problems to seriously translate "if you're anal about compliance"
anal - Wiktionary[^] - definition #3: of a person, compulsive and stubborn, obsessed with neatness and accuracy
Synonyms: fussy, pernickety, picky
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you for help me learning English. What such a insignifican word like "about" can change everything
Thank you
Bruno
modified 19-Jan-21 21:04pm.
|
|
|
|
|
Chris Maunder wrote: We're trying to find the number of records in TableOne which, when joined with TableTwo , either have no corresponding TableTwo row or the corresponding TableTwo row is not 'value'.
Either I've misunderstood your requirement, or that query isn't technically correct.
The query will find the records in TableOne which don't have any corresponding rows in TableTwo , and the records in TableOne which have at least one corresponding record in TableTwo where StringColumn is Null or not equal to 'value' . If there are multiple matching rows in TableTwo , then the rows from TableOne will be repeated.
Based on the description, I'd have thought something like this would be a better fit:
SELECT Count(1)
FROM TableOne
WHERE Not Exists
(
SELECT 1
FROM TableTwo
WHERE TableTwo.TableTwoID = TableOne.TableTwoID
And TableTwo.StringColumn = 'value'
)
That finds all the rows in TableOne which don't have a corresponding row in TableTwo with StringColumn set to 'value' .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I think this version reads cleaner (and without the quirks), but I'd be willing to bet the non-sub select version would run quicker.
Jeremy Falcon
|
|
|
|
|
Jeremy Falcon wrote: would run quicker
Indeed.
#SupportHeForShe
Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson
You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
|
|
|
|
|
|
I feel ya man. NULL has always been a special case though. It's the bastard stepchild of values. Isn't technology fun?
Jeremy Falcon
|
|
|
|
|
This proves SQL is not a real programming language.
#SupportHeForShe
Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson
You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
|
|
|
|
|
Au contraire. It's the perfect language. Job security forever.
cheers
Chris Maunder
|
|
|
|
|
LOL. Especially when you have your own company!
#SupportHeForShe
Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson
You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
|
|
|
|