Need to speed up the results of this SQL statement. Any advice?

Posted by jeffself on Stack Overflow See other posts from Stack Overflow or by jeffself
Published on 2010-03-31T13:37:56Z Indexed on 2010/03/31 13:43 UTC
Read the original article Hit count: 216

Filed under:
|

I've got the following SQL Statement that needs some major speed up. The problem is I need to search on two fields, where each of them is calling several sub-selects. Is there a way to join the two fields together so I call the sub-selects only once?

SELECT billyr, billno, propacct, vinid, taxpaid, duedate, datepif, propdesc
FROM trcdba.billspaid
WHERE date(datepif) > '01/06/2009'
AND date(datepif) <= '01/06/2010'
AND custno in
 (select custno from cwdba.txpytaxid where taxpayerno in
  (select taxpayerno from cwdba.txpyaccts where accountno in
   (select accountno from rtadba.reasacct where controlno = 1234567)))
OR custno2 in
 (select custno from cwdba.txpytaxid where taxpayerno in
  (select taxpayerno from cwdba.txpyaccts where accountno in
   (select accountno from rtadba.reasacct where controlno = 1234567)))

© Stack Overflow or respective owner

Related posts about sql

Related posts about subselect