Article View: borland.public.interbase.sql
Article #105Re: Too slow... can't think of a faster way.
From: dan palley
Date: Tue, 03 Jun 2008 17:26
Date: Tue, 03 Jun 2008 17:26
33 lines
2192 bytes
2192 bytes
"Frederic Gelinas" <frederic_gelinas@hotmail.com> wrote in message
news:4845581a$1@newsgroups.borland.com...
> Frederic Gelinas wrote:
>
>> Select sum(amount) from ARITEM a left outer join ARTRANSACTION art on
>> art.ID=a.ARTRANSACTIONID
>> where a.client=:aClient and a.customer=:aCustomer
>> and ((a.SCANDATE <= :aDate)
>> and (a.ARTRANSACTIONID is null or art.trandate > :aDate))
>
> That query is not working. It is not counting any records where
> ARITEM.ARTRANSACTIONID is null. The left outer join automatically
> rejects those records.
>
> I'm back to square 1.
Ok, the sum(amount) is potentially ambiguous. I would re-write as
sum(a.amount) just in case.
Your (a.ARTRANSACTIONID is NULL is a bit redundant; I would revise that too:
Select sum(a.amount)
from ARITEM a
left outer join ARTRANSACTION art on art.ID=a.ARTRANSACTIONID
where a.client=:aClient and
a.customer=:aCustomer and
a.SCANDATE <= :aDate and
(art.trandate is null or art.trandate > :aDate)
The left outer join will not exclude records where a.ARTRANSACTIONID is
null -- that's the whole point of using a left outer join.
Dan
Technical Details
Message-ID:
<48457e65$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!newsgate.cistron.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!feeder.erje.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<48455030@newsgroups.borland.com> <4845581a$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,a4b1f4361f20c519 X-Google-Attributes: gid114a0e,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "dan palley" <dan@trams.com> Newsgroups: borland.public.interbase.sql References: <48455030@newsgroups.borland.com> <4845581a$1@newsgroups.borland.com> Subject: Re: Too slow... can't think of a faster way. Date: Tue, 3 Jun 2008 10:26:38 -0700 Lines: 35 Organization: TRAMS X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.3959 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4133 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 66.102.131.254 Message-ID: <48457e65$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1212513893 66.102.131.254 (3 Jun 2008 10:24:53 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!newsgate.cistron.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!feeder.erje.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail