|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
optimize the select Query
<i><b>Originally posted by : Raman Garg (mrgargraman@yahoo.com)</b></i><br />I have two tables tblAddressBook and tblSalesTransaction. I want all records from tblAddressBook which are not in tblSalesTransaction. I have written following Query. I want to optimize this.<br /><br /><br />SELECT distinct tblAddressBook.ABAN8 FROM tblAddressBook Where tblAddressBook.ABAN8 not in (<br />SELECT distinct tblAddressBook.ABAN8<br />FROM tblAddressBook INNER JOIN tblSalesTransaction ON tblAddressBook.ABAN8 = tblSalesTransaction.SDAN8;<br />)<br />
|
|
#2
|
|||
|
|||
|
As the field in the address table that you are checking is unique is the same as the one you are joining on for the sales transaction then I'd just check to see if the address is not in the sales table... this saves having to do a join which will help speed things up...<br><br>SELECT distinct tblAddressBook.ABAN8 <br>FROM tblAddressBook <br>WHERE tblAddressBook.ABAN8 NOT IN (<br> SELECT DISTINCT tblSalesTransaction.SDAN8<br> FROM tblSalesTransaction)
|
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > optimize the select Query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|