473,404 Members | 2,178 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,404 software developers and data experts.

"where not in " doesn't work

Hi all,

I have written the SQL but it doesn't work

db2 "select acode from t1 where (acode) not in (select eid from t2
where iid ='0') and iid ='0'"

select nothing
but the following works

db2 "select acode from t1 where not exists (select * from t2 where iid
='0' and t1.acode=t2.eid) and crm.eod.institutionid ='0'"

I always thought where not in is equal to where not exists

anything went wrong?

Jacinle
Nov 12 '05 #1
4 29165
NOT EXISTS can yield different results from NOT IN.

NOT IN implies that data exists in the column. A predicate testing a
column containing a NULL value will not satisfy the NOT IN condition.
(verified on UDB LUW 8.1)

A null value in acode will satisfy the NOT EXISTS clause in your second
example. This is true even if t2 has a row containing a null value in eid!
Phil Sherman
Jacinle Young wrote:
Hi all,

I have written the SQL but it doesn't work

db2 "select acode from t1 where (acode) not in (select eid from t2
where iid ='0') and iid ='0'"

select nothing
but the following works

db2 "select acode from t1 where not exists (select * from t2 where iid
='0' and t1.acode=t2.eid) and crm.eod.institutionid ='0'"

I always thought where not in is equal to where not exists

anything went wrong?

Jacinle


Nov 12 '05 #2
I find that the performance of "not exists" is too slow

Is there any other syntax?

like minus in Oracle?

Philip Sherman <ps******@ameritech.net> wrote in message news:<T5***************@newssvr16.news.prodigy.com >...
NOT EXISTS can yield different results from NOT IN.

NOT IN implies that data exists in the column. A predicate testing a
column containing a NULL value will not satisfy the NOT IN condition.
(verified on UDB LUW 8.1)

A null value in acode will satisfy the NOT EXISTS clause in your second
example. This is true even if t2 has a row containing a null value in eid!
Phil Sherman
Jacinle Young wrote:
Hi all,

I have written the SQL but it doesn't work

db2 "select acode from t1 where (acode) not in (select eid from t2
where iid ='0') and iid ='0'"

select nothing
but the following works

db2 "select acode from t1 where not exists (select * from t2 where iid
='0' and t1.acode=t2.eid) and crm.eod.institutionid ='0'"

I always thought where not in is equal to where not exists

anything went wrong?

Jacinle

Nov 12 '05 #3
ja***********@hongkong.com (Jacinle Young) wrote in message news:<12**************************@posting.google. com>...
I find that the performance of "not exists" is too slow

Is there any other syntax?

like minus in Oracle?

Philip Sherman <ps******@ameritech.net> wrote in message news:<T5***************@newssvr16.news.prodigy.com >...
NOT EXISTS can yield different results from NOT IN.

NOT IN implies that data exists in the column. A predicate testing a
column containing a NULL value will not satisfy the NOT IN condition.
(verified on UDB LUW 8.1)

A null value in acode will satisfy the NOT EXISTS clause in your second
example. This is true even if t2 has a row containing a null value in eid!
Phil Sherman
Jacinle Young wrote:
Hi all,

I have written the SQL but it doesn't work

db2 "select acode from t1 where (acode) not in (select eid from t2
where iid ='0') and iid ='0'"

select nothing
but the following works

db2 "select acode from t1 where not exists (select * from t2 where iid
='0' and t1.acode=t2.eid) and crm.eod.institutionid ='0'"

I always thought where not in is equal to where not exists

anything went wrong?

Jacinle


SELECT acode from t1 where ...
EXCEPT
SELECT eid from t2 where iid='0'
Nov 12 '05 #4
Use EXPLAIN to find out why your performance is poor. It can usually be
tracked down to missing indices or poor statistics. "Not exists" used to be
slow, but IBM added semijoin processing to DB2 a while back.

Changing the syntax will usually have no effect on performance issues in
DB2.

"Jacinle Young" <ja***********@hongkong.com> wrote in message
news:12**************************@posting.google.c om...
I find that the performance of "not exists" is too slow

Is there any other syntax?

like minus in Oracle?

Philip Sherman <ps******@ameritech.net> wrote in message

news:<T5***************@newssvr16.news.prodigy.com >...
NOT EXISTS can yield different results from NOT IN.

NOT IN implies that data exists in the column. A predicate testing a
column containing a NULL value will not satisfy the NOT IN condition.
(verified on UDB LUW 8.1)

A null value in acode will satisfy the NOT EXISTS clause in your second
example. This is true even if t2 has a row containing a null value in eid!

Phil Sherman
Jacinle Young wrote:
Hi all,

I have written the SQL but it doesn't work

db2 "select acode from t1 where (acode) not in (select eid from t2
where iid ='0') and iid ='0'"

select nothing
but the following works

db2 "select acode from t1 where not exists (select * from t2 where iid
='0' and t1.acode=t2.eid) and crm.eod.institutionid ='0'"

I always thought where not in is equal to where not exists

anything went wrong?

Jacinle

Nov 12 '05 #5

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

Similar topics

10
by: KENNY L. CHEN | last post by:
Dear experts, I have two tables in my Oracle 8i database: TEST (COL1,COl2,REC_NO) and TEST1 (COL1,COL2,REC_NO). Both tables are unique-indexed on (COL1,COL2,REC_NO). I think the following...
25
by: delerious | last post by:
I see some code examples like this: <DIV onmouseover="this.style.background='blue'"> and other code examples like this: <DIV onmouseover="javascript:this.style.background='blue'"> Which...
2
by: Ellen Manning | last post by:
Using A2K. In my table I have the field "Grant" which can have a value or be null. I have a query that counts the number of records and has a Where clause on the Grant field. The query won't...
6
by: **Developer** | last post by:
I have a couple of instances where using "Auto" did not work so I tried the "A" version of the DLL and it works. Tried the "W" version and it doesn't. Anyone have any idea why that might...
0
by: Liorm | last post by:
Hi, I found URLEncode differs in ASP and ASP.NET - when I encode "-" in ASP it gives me %2D, and in ASP.NET it gives me "-". Why? Does it happen with other characters? And how can I get the...
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
94
by: Samuel R. Neff | last post by:
When is it appropriate to use "volatile" keyword? The docs simply state: " The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock...
1
by: itamar82 | last post by:
I am getting the following error: Microsoft OLE DB Provider for SQL Server error '80040e14' Incorrect syntax near the keyword 'WHERE'. for the sql below: SELECT TourId FROM (SELECT...
19
by: Daniel Pitts | last post by:
I have std::vector<Base *bases; I'd like to do something like: std::for_each(bases.begin(), bases.end(), operator delete); Is it possible without writing an adapter? Is there a better way? Is...
19
by: maya | last post by:
hi, so what is "modern" javascript?? the same as "DOM-scripting"? i.e., editing content (or changing appearance of content) dynamically by massaging javascript objects, html elements, etc? ...
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: 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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.