Link to home
Start Free TrialLog in
Avatar of markloessi
markloessiFlag for Afghanistan

asked on

Not Equals in MS Access Query

From what I've seen this should work however it does not.
User generated imagealthough the SQL looks as I'd expect
...
WHERE (((BI.NRS_STATION)<>[NRS_STATION_IGNORE].[NRS_STATION_CODE]) AND...

Open in new window

I'm wanting to 'not include' any of the nursing stations that are present in the nrs_station_ignore table.

Thoughts?
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

You can use :
WHERE (BI.NRS_STATION Not In (Select NRS_STATION_CODE] from [NRS_STATION_IGNORE]))
Avatar of Member_2_276102
Member_2_276102

Because there is an "AND" following your 'not equal' condition, that has a good chance of causing the problem. Whenever 'not equal' is combined with an "AND" in a WHERE clause, the entire WHERE clause needs to be known.

It's not always intuitive why it goes wrong, but it's usually easy to spot.

It might even affect the result with "NOT IN()".

Please show the entire clause if the problem continues.

Tom
I don't see any joins with the tables you have shown in your screenshot.

I don't know if they are part of your SQL (Query) or not, but just want to mentioned it in case they are.
To clarify, the "AND" isn't necessarily exactly the problem; but it indicates that there is more of the WHERE clause than we can see. It will be the totality of the WHERE clause that will be important when "not equal" is part of it.

RichardRost's suggestion to build the WHERE clause a segment at a time is a very good one. At some point of complexity, you should see that results get off track. That will be the point when the parts of the WHERE clause need explanation.

Tom
It would be very helpful if you can post the whole SQL statement you have.
ASKER CERTIFIED SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland 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
Agreed with peter57r

this is best option

WHERE (BI.NRS_STATION Not In (Select NRS_STATION_CODE] from [NRS_STATION_IGNORE]))