Using MS Access/Hi

Advertisement


Question
Hi

I have an MS access 2013 query where I need to exclude results from an existing query i.e I have 3 tables for the first 2 tables I am doing an unmatched query against the customer number and from the third table I need to exclude all customer numbers from the results.

The Query Below

SELECT ICMS_PSTN.CUSTOMER_NUMBER, ICMS_PSTN.ACCOUNT_NUMBER, ICMS_PSTN.ACCOUNT_DESCRIPTION
FROM (ICMS_PSTN LEFT JOIN SIEBEL_PSTN ON ICMS_PSTN.CUSTOMER_NUMBER = SIEBEL_PSTN.CUSTOMER_NUMBER) LEFT JOIN ICMS_PSTN_EXCLUDE_CUST_NUMBER ON SIEBEL_PSTN.CUSTOMER_NUMBER = ICMS_PSTN_EXCLUDE_CUST_NUMBER.CUSTOMER_NUMBER
WHERE (((ICMS_PSTN.CUSTOMER_NUMBER)<>[ICMS_PSTN_EXCLUDE_CUST_NUMBER].[CUSTOMER_NUMBER]) AND ((SIEBEL_PSTN.CUSTOMER_NUMBER) Is Null));

Table 1 is ICMS_PSTN.CUSTOMER_NUMBER
Table 2 is SIEBEL_PSTN.CUSTOMER_NUMBER
Table 3 is ICMS_PSTN_EXCLUDE_CUST_NUMBER.CUSTOMER_NUMBER

The query runs but hangs up - Note there are nearly 2 million records in each table i.e table 1 and 2. Table 3 has 100000+ records

Can you please check this looks right

Your help is much appreciated!

Thanks

Shay

Answer
Try using a Subquery instead something like.

SELECT ICMS_PSTN.CUSTOMER_NUMBER, ICMS_PSTN.ACCOUNT_NUMBER, ICMS_PSTN.ACCOUNT_DESCRIPTION
FROM ICMS_PSTN LEFT JOIN SIEBEL_PSTN ON ICMS_PSTN.CUSTOMER_NUMBER = SIEBEL_PSTN.CUSTOMER_NUMBER
WHERE ICMS_PSTN.CUSTOMER_NUMBER NOT IN(SELECT Customer_Number FROM ICMS_PSTN_EXCLUDE_CUST_NUMBER);

Hope this helps,
Scott<>
Blog: http://scottgem.wordpress.com
Website: http://www.diamondassoc.com
Microsoft Access MVP 2007
Author: Microsoft Office Access 2007 VBA  

Using MS Access

All Answers


Answers by Expert:


Ask Experts

Volunteer


Scottgem

Expertise

I can answer almost all types of questions relating to Microsoft Access usage and application design. My strengths are database and interface design.

Experience

I've been designing databases for over 25 years working with dBase, FoxPro, Approach and Access.

Organizations
Author of Microsoft Office Access 2007 VBA
Techncial Editor for Special Edition Using Microsoft Access 2007 and Access 2007 Forms, Reports & Queries From Que Publishing

Education/Credentials
Brooklyn College BA

©2016 About.com. All rights reserved.