Can you rework it to use a correlated sub-query along the lines:

SELECT a.f1,a.f2,b.ff1,b.ff2 FROM table1 a LEFT OUTER JOIN table2 b ON a.id
= b.id AND b.ff3 = 'T' and exists
(select 1 from table2 where
WHERE mydate BETWEEN '3/4/2002' AND '3/6/2002' AND ff4 = 'somevalue' and
id = a.id and ff3 = a.ff3)

Just a suggestion...


Chuck McElwee
etech solutions inc
www.etechsolutions.com


-----Original Message-----
From: Adrian Cesana [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 06, 2002 7:41 PM
To: CF-Talk
Subject: slooow query using JOIN


This queries performance is acceptable (about 1 second) when run like this:

SELECT a.f1,a.f2,b.ff1,b.ff2 FROM table1 a LEFT OUTER JOIN table2 b ON a.id
= b.id AND b.ff3 = 'T'
WHERE a.mydate BETWEEN '3/4/2002' AND '3/6/2002' AND b.ff4 = 'somevalue'


It is terrible (60 seconds) when run like this:
SELECT a.f1,a.f2,b.ff1,b.ff2 FROM table1 a LEFT OUTER JOIN table2 b ON a.id
= b.id AND b.ff3 = 'T'
WHERE b.mydate BETWEEN '3/4/2002' AND '3/6/2002' AND b.ff4 = 'somevalue'


I need the date range to come from the b.maydate.  The field is indexed. If
I run another query directy on table2 b without a JOIN and using b.mydate
for some daterange it is quite fast.  Any idea how to speed this up?

Thanks,Adrian

MSSQL 7

______________________________________________________________________
Why Share?
  Dedicated Win 2000 Server � PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER
  Instant Activation � $99/Month � Free Setup
  http://www.pennyhost.com/redirect.cfm?adcode=coldfusionc
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to