?
Solved

basic query access not in

Posted on 2013-12-18
10
Medium Priority
?
386 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 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
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

777 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