Solved

basic query access not in

Posted on 2013-12-18
10
365 Views
Last Modified: 2013-12-18
I have a simple DB with 2 tables (all and exclude), in both tables is an "accountname" field.

I need to run a select * from all where the accountname filed is not equal to the accountname field in the exclude table?

Can anyone give me a heads up on the SQL to acheive something like this in access 2010? None of the join options seemed appropriate in design view.
0
Comment
Question by:pma111
  • 5
  • 5
10 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39726762
Try this:

SELECT a.* 
FROM [All] a LEFT JOIN [Exclude] e ON a.accountname = e.accountname
WHERE e.accountname IS NULL

Open in new window

0
 
LVL 3

Author Comment

by:pma111
ID: 39726791
Is it definately a left join because that query has ran ok but returned all results where the exclude entries are also in the output, when I need to cut down the results to those which dont include the exclude acctnames.
0
 
LVL 3

Author Comment

by:pma111
ID: 39726793
or perhaps the = is wrong? should it be not =
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 3

Author Comment

by:pma111
ID: 39726827
basically if table e includes user 7 , user 32 and user 33

but table a contains user 1... user 100

The output of the query should list all users except user 7, user 32 and user 33.

like a select all rows unless the username is included in the list of usernames in the exlude table.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39726843
Can you post the query exactly as you implemented it in your database?

The LEFT JOIN, combined with the IS NULL in the WHERE clause is the basic setup for an 'unmatched query'.... in this case the goal was to select all records in table a that did not have a matching record in table b (which lists names to exclude)
0
 
LVL 3

Author Comment

by:pma111
ID: 39726859
SELECT a.*
FROM [mailboxACL] a LEFT JOIN [exclude] e ON a.Identity = e.acctname
WHERE e.acctname IS NULL

The above has returned entries in the identity column that are entries in the "e.acctname" in the other table.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39726868
An alternative approach  would be:

SELECT a.* 
FROM [All] a 
WHERE a.accountname NOT IN (SELECT e.accountname FROM [Exclude] e)

Open in new window


But the LEFT JOIN method if we can get that working would likely have better performance than the NOT IN method.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39726885
What are the datatypes for Identity and acctname in their respective table designs?
0
 
LVL 3

Author Comment

by:pma111
ID: 39726888
worked, was my mistake (uising the wrong field )

thanks
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39726907
Glad to help out :-)
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Question about DB Schema 27 56
SYbase 4 31
Help with DoEvents 8 28
Experience with VBA code that changes unexplicably? 8 24
Outlook Free & Paid Tools
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question