473,394 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

SQL Null handling in predicate evaluation involving IN

Greetings,

I have a question about how nulls are handled in "IN" clauses.. I
understand the operation null = anyvalue is undefined. Please examine
the following example.

drop table one
DB20000I The SQL command completed successfully.

create table one( first char(3), next1 int) in mcd_fl_coord3
DB20000I The SQL command completed successfully.

drop table two
DB20000I The SQL command completed successfully.

create table two( second char(3), next2 int) in mcd_fl_coord3
DB20000I The SQL command completed successfully.

insert into one (next1) values (2)
DB20000I The SQL command completed successfully.

insert into one (first,next1) values ('one',1)
DB20000I The SQL command completed successfully.

insert into two (next2) values (3)
DB20000I The SQL command completed successfully.

insert into two (next2) values (4)
DB20000I The SQL command completed successfully.

insert into two (second,next2) values ('two',5)
DB20000I The SQL command completed successfully.

insert into two (second,next2) values ('one',6)
DB20000I The SQL command completed successfully.

select * from one

FIRST NEXT1
----- -----------
- 2
one 1

2 record(s) selected.
select * from two

SECOND NEXT2
------ -----------
- 3
- 4
two 5
one 6

4 record(s) selected.
select first from one

FIRST
-----
-
one

2 record(s) selected.
<---- as expected

select second from two where second in (select first from one )

SECOND
------
one

1 record(s) selected.
<---- as expected

select second from two where second not in (select first from one )

SECOND
------

0 record(s) selected.

<---- not expected shouln't I get 'two'

select second from two where second not in (select first from one
where first is not null)

SECOND
------
two

1 record(s) selected.
<--- now I get the expected result when nulls are filterd in the "IN"
clause
Why is this? I presume this has something to do with the fact that
equality operations on nulls are undefined but it doesn't seem
consistant to me b/c there are nulls in the other table(second) too
which are not filterd in the last statement but I still get the
expected result. Can Anybody explain the logic here...I am probably
overlooking something obvious here...

TIA,
Scott
Nov 12 '05 #1
1 3133
Please search comp.databases with "nulls in subselect".
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Joel | last post by:
Hi, I added a field to my company table (PBV_rstCompany.Fields("Installer")) the default value of the field is Null. I place this If statement and it doesn't work If...
19
by: Baldur Norddahl | last post by:
Hi, How come "X=null" is not the same as "X is null"? I got a few selects with queries like this: select * from foo where customer=#customer# or (#customer# is null and customer is null) ...
22
by: Christopher Benson-Manica | last post by:
Is adding 0 to a pointer to non-void that is equal to NULL legal? int *p=NULL; p+=0; -- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org ...
4
by: Shwetabh | last post by:
Hi, My question is, is there any difference between a NULL and a Blank (Unknown, Not Applicable) field in MS SQL or are they the same? Awaiting your comments, Regards
1
by: SteZgr | last post by:
I have implemented in .NET 2.0 a custom XPathNavigator for Xpath filtering on an object tree. So far it works. While analyzing the performance, I have noticed a lot of MoveToNextAttribute calls. ...
17
by: Mark A | last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP 11). Using the SAMPLE database, tables EMP and EMLOYEE. In the followng stored procedure, 2 NULL columns (COMM) are...
22
by: dvestal | last post by:
Suppose I have this: class C { public delegate void MyEventHandler(); public event MyEventHandler MyEvent; public void foo() { MyEvent(); // NullReferenceException? } }
32
by: silpau | last post by:
hi, i am a bit confused on expression evaluation order in expressions involving unary increment.decrement operators along with binary operators. For example in the following expression x...
3
by: Arun Srinivasan | last post by:
I have a query that has 5 predicates, scanning a table of 400+ million rows and I have built indexes getting help from design advisor and other tools. The cost of that query is really low. But I...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.