Link to home
Start Free TrialLog in
Avatar of Pau Lo
Pau Lo

asked on

basic query access not in

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.
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Pau Lo
Pau Lo

ASKER

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.
Avatar of Pau Lo

ASKER

or perhaps the = is wrong? should it be not =
Avatar of Pau Lo

ASKER

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.
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)
Avatar of Pau Lo

ASKER

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.
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.
What are the datatypes for Identity and acctname in their respective table designs?
Avatar of Pau Lo

ASKER

worked, was my mistake (uising the wrong field )

thanks
Glad to help out :-)