Solved

basic query access not in

Posted on 2013-12-18
10
358 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
 
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
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.

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

My experience with Windows 10 over a one year period and suggestions for smooth operation
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, when working with VBA, learn some techniques for writing readable and easily maintained code.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now