473,467 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Explanation???

I've found something in access I can't explain.....

I have two tables:

CLIENTS_COMPANY_A:
CodA Int.
NameA Text(40)
NIFA TEXT(15)

CLIENTS_COMPANY_B:
CodB Int.
NameB Text(40)
NIFB TEXT(15)

A want to know which clients of company A aren't on company B, with the next
SQL: (using the field NIF)

Of course there is clients on A which NIF's aren't found on B

select * from clients_company_A
where NIFA not in (select NIFB from clients_company_B)

It gives back 0 rows !!!!!!

There are NULL values on NIFA and in NIFB, so I retried:

select * from clients_company_A
where NIFA <> ""
and NIFA not in (select NIFB from clients_company_B where NIFB<>"")

This one gives back all the rows I where looking for, but I don't understand
why the first SQL didn't work.

I've trid the same on Mysql and the first SQL works ok.

Is there any explanation for this? Is access working properly?
Thanks in advance, Jon

Dec 7 '05 #1
16 1531
"Jon Berraondo" <jo***********@elektra-sa.es> wrote in message
news:dn**********@domitilla.aioe.org...
I've found something in access I can't explain.....

I have two tables:

CLIENTS_COMPANY_A:
CodA Int.
NameA Text(40)
NIFA TEXT(15)

CLIENTS_COMPANY_B:
CodB Int.
NameB Text(40)
NIFB TEXT(15)

A want to know which clients of company A aren't on company B, with the
next
SQL: (using the field NIF)

Of course there is clients on A which NIF's aren't found on B

select * from clients_company_A
where NIFA not in (select NIFB from clients_company_B)

It gives back 0 rows !!!!!!

There are NULL values on NIFA and in NIFB, so I retried:

select * from clients_company_A
where NIFA <> ""
and NIFA not in (select NIFB from clients_company_B where NIFB<>"")

This one gives back all the rows I where looking for, but I don't
understand
why the first SQL didn't work.

I've trid the same on Mysql and the first SQL works ok.

Is there any explanation for this? Is access working properly?


Do you have your text fields set to allow zero-length strings?

Keith.
www.keithwilby.com
Dec 7 '05 #2
Hmm, all your second statement does is exclude NIFAs which are not empty
strings and shouldn't affect Null values (which would be excluded anyway as
they wouldn't equate).

Personally as "not in" is not optimised in Access I would have gone with

SELECT
*
FROM
clients_company_A
LEFT OUTER JOIN
clients_company_B
ON
NIFA = NIFB
WHERE
NIFB Is Not Null
--
Terry Kreft

"Jon Berraondo" <jo***********@elektra-sa.es> wrote in message
news:dn**********@domitilla.aioe.org...
I've found something in access I can't explain.....

I have two tables:

CLIENTS_COMPANY_A:
CodA Int.
NameA Text(40)
NIFA TEXT(15)

CLIENTS_COMPANY_B:
CodB Int.
NameB Text(40)
NIFB TEXT(15)

A want to know which clients of company A aren't on company B, with the
next
SQL: (using the field NIF)

Of course there is clients on A which NIF's aren't found on B

select * from clients_company_A
where NIFA not in (select NIFB from clients_company_B)

It gives back 0 rows !!!!!!

There are NULL values on NIFA and in NIFB, so I retried:

select * from clients_company_A
where NIFA <> ""
and NIFA not in (select NIFB from clients_company_B where NIFB<>"")

This one gives back all the rows I where looking for, but I don't
understand
why the first SQL didn't work.

I've trid the same on Mysql and the first SQL works ok.

Is there any explanation for this? Is access working properly?
Thanks in advance, Jon

Dec 7 '05 #3
"Terry Kreft" <te*********@mps.co.uk> wrote in
news:Xj********************@karoo.co.uk:
Personally as "not in" is not optimised in Access I would have
gone with


Who says it's not optimized? No, SHOWPLAN does not show any
optimization for it, but that's because SHOWPLAN never implemented
handling of any form of subqueries. That doesn't mean the query
optimizer is not optimizing subqueries, only that you can't find out
how using SHOWPLAN.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Dec 8 '05 #4
SELECT DISTINCT cca.* FROM CLIENTS_COMPANY_A cca
LEFT OUTER JOIN CLIENTS_COMPANY_B ccb
ON cca.NIFA=ccb.NIFB
WHERE
Nz(cca.NIFA,"") <> ""
AND
Nz(ccb.NIFB,"") = ""

or

WHERE
cca.NIFA Is Not Null
AND
ccb.NIFB Is Null

The latter can be used if zero length strings are not allowed for
cca.NIFA and ccb.NIFB. If these fields are indexed then Rushmore may
optimize the query and make the JOIN many times faster. As you allow
Nulls, this may be offset or may not work at all.

In my experience "Not In" = "The query will finish executing but !!!!
not in !!!! your lifetime".

Dec 8 '05 #5
Everyone has solutions; this is mine:

SELECT DISTINCT cca.* FROM CLIENTS_COMPANY_A cca
LEFT JOIN CLIENTS_COMPANY_B ccb
ON cca.NIFA=ccb.NIFB
WHERE
Nz(cca.NIFA,"") <> ""
AND
Nz(ccb.NIFB) = ""

If you're not allowing zero length strings then you can avoid Nz with
WHERE
cca.NIFA Is Not Null
AND
ccb.NIFB Is Null

In the latter case maybe Rushmore will run the query a gazillion times
faster assuming it creates or has available to it appropriate indexes.

BTW "Not In" is an abbreviation for "This query will finish running but
!not in! your lifetime".

YMMV.

Dec 8 '05 #6
Well, I say it's not optimised and I've seen the same statemenmt over the
years from a number of people.

I don't quite understand the relevance of the rest of your posting, seems a
bit of a religious argument to me.
--
Terry Kreft

"David W. Fenton" <dX********@bway.net.invalid> wrote in message
news:Xn**********************************@216.196. 97.142...
"Terry Kreft" <te*********@mps.co.uk> wrote in
news:Xj********************@karoo.co.uk:
Personally as "not in" is not optimised in Access I would have
gone with


Who says it's not optimized? No, SHOWPLAN does not show any
optimization for it, but that's because SHOWPLAN never implemented
handling of any form of subqueries. That doesn't mean the query
optimizer is not optimizing subqueries, only that you can't find out
how using SHOWPLAN.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc

Dec 8 '05 #7
"Terry Kreft" <te*********@mps.co.uk> wrote in
news:Kc********************@karoo.co.uk:
"David W. Fenton" <dX********@bway.net.invalid> wrote in message
news:Xn**********************************@216.196. 97.142...
"Terry Kreft" <te*********@mps.co.uk> wrote in
news:Xj********************@karoo.co.uk:
Personally as "not in" is not optimised in Access I would have
gone with
Who says it's not optimized? No, SHOWPLAN does not show any
optimization for it, but that's because SHOWPLAN never
implemented handling of any form of subqueries. That doesn't mean the query optimizer is not optimizing subqueries, only that you
can't find out how using SHOWPLAN.


Well, I say it's not optimised . . .


Yes, it clearly doesn't use the indexes in some cases, but it seems
to me that in others, it *does* use the indexes. I've never been
able to figure out exactly why NOT IN (and IN) seem well-optimized
in some cases and not in others.
. . . and I've seen the same statemenmt
over the years from a number of people.
What statement? That it's not optimized? That SHOWPLAN doesn't tell
you whether it is or not?
I don't quite understand the relevance of the rest of your
posting, seems a bit of a religious argument to me.


Well, so far as I can tell, you have no actual factual basis for
claiming that NOT IN is not optimized by Jet. The only possible
justification one might have for that is SHOWPLAN, and I was only
pointing out that SHOWPLAN is actually completely silent on the
issue and can't be used as evidence to suggest that NOT IN is not
optimized.

Do you have any factual basis for the absolute claim that NOT IN is
not optimized, other than the known fact that it sometimes doesn't
use available indexes?

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Dec 8 '05 #8
David W. Fenton wrote:
Well, so far as I can tell, you have no actual factual basis for
claiming that NOT IN is not optimized by Jet. The only possible
justification one might have for that is SHOWPLAN, and I was only
pointing out that SHOWPLAN is actually completely silent on the
issue and can't be used as evidence to suggest that NOT IN is not
optimized.

Do you have any factual basis for the absolute claim that NOT IN is
not optimized, other than the known fact that it sometimes doesn't
use available indexes?

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc


Terry's explanation matches what I've seen. I've tried both NOT IN and
LEFT JOIN on indexed fields and found that NOT IN can be easily a
factor of 10 or 20 times slower than the LEFT JOIN. I suspect that the
difference has little to do with indices although the lack of them
should really bring the query to a crawl when NOT IN is used. It seems
like the NOT IN syntax checks the NOT list for each record and is
especially slow on larger recordsets. I don't have any hard, cold
justification for this similar to using SHOWPLAN. My comments are
based entirely on casual empirical observation. Perhaps I am using NOT
IN incorrectly. If anyone can provide a reference to the facts I would
appreciate it. Thanks for pointing out that SHOWPLAN can exclude
subquery optimization.

James A. Fortune

Dec 9 '05 #9
I'll expand the first paragraph as it seems that it is not clear to you.

Well, I say it's not optimised and over the years I have seen a number of
people state that it is not optimised.

Hmmm, the SHOWPLAN part of your post I found slightly confusing as you
seemed to be saying that the lack of proof by SHOWPLAN was proof that my
statement was false, hence my comment that it seemed a religious statement.

I do remember reading an article about this quite a number of years ago but
as my memory is lousy so I cannot for the life of me point you to it. On
that basis I would have to say no I cannot present a written statement as
fact to your satisfaction, however I have had a number of experiences where
left outer join has shown a dramatic performance improvement over NOT IN.

For example, a support call (last week) from one of our implementors
involved a query he had created which used NOT IN to exclude some records.
He reported that performance was abysmal, with the query taking minutes to
run. I talked him through restructuring the query using a left outer join
and excluding null values on the RHS of the join. We confirmed the SQL and
I asked him to run the query at his leisure and ring back if there were any
problems, I had barely finished the sentence when he said he had already run
it, it had finished and he could see the results. So from minutes to
approximately a second.

--
Terry Kreft

"David W. Fenton" <dX********@bway.net.invalid> wrote in message
news:Xn**********************************@216.196. 97.142...
"Terry Kreft" <te*********@mps.co.uk> wrote in
news:Kc********************@karoo.co.uk:
"David W. Fenton" <dX********@bway.net.invalid> wrote in message
news:Xn**********************************@216.196. 97.142...
"Terry Kreft" <te*********@mps.co.uk> wrote in
news:Xj********************@karoo.co.uk:

Personally as "not in" is not optimised in Access I would have
gone with

Who says it's not optimized? No, SHOWPLAN does not show any
optimization for it, but that's because SHOWPLAN never
implemented handling of any form of subqueries. That doesn't mean the query optimizer is not optimizing subqueries, only that you
can't find out how using SHOWPLAN.


Well, I say it's not optimised . . .


Yes, it clearly doesn't use the indexes in some cases, but it seems
to me that in others, it *does* use the indexes. I've never been
able to figure out exactly why NOT IN (and IN) seem well-optimized
in some cases and not in others.
. . . and I've seen the same statemenmt
over the years from a number of people.


What statement? That it's not optimized? That SHOWPLAN doesn't tell
you whether it is or not?
I don't quite understand the relevance of the rest of your
posting, seems a bit of a religious argument to me.


Well, so far as I can tell, you have no actual factual basis for
claiming that NOT IN is not optimized by Jet. The only possible
justification one might have for that is SHOWPLAN, and I was only
pointing out that SHOWPLAN is actually completely silent on the
issue and can't be used as evidence to suggest that NOT IN is not
optimized.

Do you have any factual basis for the absolute claim that NOT IN is
not optimized, other than the known fact that it sometimes doesn't
use available indexes?

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc

Dec 9 '05 #10
"Terry Kreft" <te*********@mps.co.uk> wrote in
news:Jm********************@karoo.co.uk:
For example, a support call (last week) from one of our
implementors involved a query he had created which used NOT IN to
exclude some records. He reported that performance was abysmal,
with the query taking minutes to run. I talked him through
restructuring the query using a left outer join and excluding null
values on the RHS of the join. We confirmed the SQL and I asked
him to run the query at his leisure and ring back if there were
any problems, I had barely finished the sentence when he said he
had already run it, it had finished and he could see the results.
So from minutes to approximately a second.


I am not disagreeing that NOT IN is not reliably optimized. I am
only disagreeing that it is *never* optimized, as I've used it in
circumstances where it caused no performance problems at all (with
reasonably large recordsets).

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Dec 10 '05 #11
I'm not talking about optimization but about the posible bug on the jet
engine... This has brought a lot of problems to me.

Thanks again, Jon

ji********@compumarc.com wrote:
David W. Fenton wrote:
Well, so far as I can tell, you have no actual factual basis for
claiming that NOT IN is not optimized by Jet. The only possible
justification one might have for that is SHOWPLAN, and I was only
pointing out that SHOWPLAN is actually completely silent on the
issue and can't be used as evidence to suggest that NOT IN is not
optimized.

Do you have any factual basis for the absolute claim that NOT IN is
not optimized, other than the known fact that it sometimes doesn't
use available indexes?

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc


Terry's explanation matches what I've seen. I've tried both NOT IN and
LEFT JOIN on indexed fields and found that NOT IN can be easily a
factor of 10 or 20 times slower than the LEFT JOIN. I suspect that the
difference has little to do with indices although the lack of them
should really bring the query to a crawl when NOT IN is used. It seems
like the NOT IN syntax checks the NOT list for each record and is
especially slow on larger recordsets. I don't have any hard, cold
justification for this similar to using SHOWPLAN. My comments are
based entirely on casual empirical observation. Perhaps I am using NOT
IN incorrectly. If anyone can provide a reference to the facts I would
appreciate it. Thanks for pointing out that SHOWPLAN can exclude
subquery optimization.

James A. Fortune


Dec 12 '05 #12
Tell us about "the posible bug on the jet engine", please.

Dec 12 '05 #13
Lyle Fairfield wrote:
Tell us about "the posible bug on the jet engine", please.


If I'm not wrong, the SQL sentence written at the begining of this post is
correct, and it should give back the data I was looking for instead of
giving 0 rows back.

Why the second sentence (especifying <> "") works fine?

Have I correctly understood there is a problem of timeOut for the second
sentence?
If yes, I think this a bug, isn't it?

Thanks, Jon

Dec 12 '05 #14
I would not classify something as a bug unless it and everything
surrounding it had been very thorougly examined by several capable
devlopers/programmers etc.
I think JET makes few promises about how it may deal with nulls and
zero length strings and probably rightly so. And "not" can be a logical
nightmare when it is NOT handled carefully. If NIFA one is a zero
length string and NIFB two is a zero length string what does that
signify? Is NIFA one = NIFB one? In VBA the answer is Yes. But when we
are looking at the IN operator in SQL is this (the two zero length
strings) likely to indicate some relationship between the two records
which hold them. Maybe a trivial relationship, ie, we don't know what
they are, but not anything more.
I don't have any aunts. You don't have any aunts. So we're cousins,
right?

Dec 12 '05 #15
Lyle Fairfield wrote:

Hi Lyle, thanks for thew answer.
I would not classify something as a bug unless it and everything
surrounding it had been very thorougly examined by several capable
devlopers/programmers etc.
Ok, but you got to start from any point...
Thats what I'm looking for: somebody able of exlpaining to me the reason for
this behaviour.... I don't like answers like "you have to manage "NOT IN"
carefully: I would prefer to know WHY my sentence didn't retrieve any row
(and it was the simplest of sentences)

I've tried it on Access 97, 2000, and 2003 with the same result.... No
matches.

SQL Server , MySql and Postgress do it correctly: they found matches: X==X,
even if there are zero lengths. You can have thousands of records with zero
lengths, but in my opinion it should give back coincidences like NIFA="Jon"
and NIFB="Jon". Shouldn't access compare every record ??
I think JET makes few promises about how it may deal with nulls and
zero length strings and probably rightly so.
I know what is Jet make to. I know it is not a professional RRBBDD system,
but I thought I could trust it during a VERY simple SQL sentence. Now I
know I can't.
And "not" can be a logical
nightmare when it is NOT handled carefully. I do NOT thing that manage " NOT IN" can be a nigthmare to ANY database
system....
If NIFA one is a zero
length string and NIFB two is a zero length string what does that
signify? Is NIFA one = NIFB one? In VBA the answer is Yes. But when we
are looking at the IN operator in SQL is this (the two zero length
strings) likely to indicate some relationship between the two records
which hold them. Maybe a trivial relationship, ie, we don't know what
they are, but not anything more. I was lloking for coincidences: what you say explains is why zero lenght
strings aren't found as coincidences, but does not explain why it doesn'
find (NiFA="jon"==NIFB="jon").
You just need two records in each table: if each one has zero lenth string
the sentence won't work.
I don't have any aunts. You don't have any aunts. So we're cousins,
right?


I'm sorry, but I don't understand this... My english is quit poor.
What that means, please?

Thanks again, Lyle.
Best regards, Jon

Dec 13 '05 #16
OK
I can understand your wanting to KNOW WHY.
When, if I get some time I'll examine this more closely and try to
identify why MS-SQL works and JET does not. And when I do I'll report
if I find anything. But don't hold your breath, please.
Forget about the Cousins thing; it was a misplaced auntalogy. No, just
forget about it.

Dec 13 '05 #17

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

Similar topics

2
by: Swartz | last post by:
Hi all. I'm building a development webserver (redhat-based). I'm trying to compile PHP (v4.3.4 if anyone cares) with all the features I might require in the near future. I've ran into a problem...
0
by: Premshree Pillai | last post by:
Hey, For the uninitiated: an explanation of makeExe.py (http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/266471), in the form of an article, “Create Python Executables Automatically”, is...
3
by: David MacQuigg | last post by:
I am writing a chapter for teaching OOP in Python. This chapter is intended as a brief introduction to replace the more complete discussion in Learning Python, 2nd ed, pp. 295-390. I need to...
2
by: MatthewRoberts | last post by:
Howdy All, I have a Windows Service that often stops in its tracks with no exception and no explanation on our QA system. During testing on the development machine, it can handle any workload,...
1
by: jimfortune | last post by:
From: http://groups-beta.google.com/group/comp.databases.ms-access/msg/769e67e3d0f97a90?hl=en& Errata: 19 solar years = 2939.6018 days should be 19 solar years = 6939.6018 days Easter...
2
by: Dave Taylor | last post by:
Is there a decent explanation of how menu merging with MDI forms work in VB.NET? I've read through the online help and it still seems that whenever I change menus around or whatever, it breaks...
12
by: jacob navia | last post by:
Hi I am writing this tutorial stuff again in the holidays and I came across this problem: The "width" field in printf is a minimum width. Printf will not truncate a field. for instance:...
4
by: dismantle | last post by:
Hi all, this is my 3rd week in studying VB codes and i came across with this codes from a online tutorial about classes. Public Function MiddleInitial() As String MiddleInitial =...
6
by: WolfgangS | last post by:
Ok first off, i am a total beginner at this groups stuff and i have no clue how this works. This is probabaly the wrong group for my problem but i will post it anyways. Learning by doing right? ...
16
by: DamienS | last post by:
In the interests of me saving hair, can someone please explain to me what's going on below? Why doesn't == work in comparing two int's when cast as objects? They're the same type. Note that it...
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
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,...
1
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...
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,...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.