Using NOT to exclude records in query design (1 Viewer)

uplink600

Registered User.
Local time
Today, 21:57
Joined
Mar 18, 2004
Messages
69
I'm using the NOT expression to exclude certain records in a query. I can't seem to get it working using more that one exclusion. For example I would like to return records for all sales people excluding............

Dave Smith
Alan Jones
Alice Carter

Please advise how this works in query design.

Thanks

Vere
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:57
Joined
Feb 28, 2001
Messages
27,146
When you do your query grid, before you save it, switch to SQL to see how it makes the list.

Let's say your name field is called WholeName and that your spelling was exactimundo on the names. (Spelling of the individual names must be exact for this to work anyway.)

The part of the SQL that you want to see is

Code:
..."WHERE ( [WholeName] <> "Dave Smith" ) AND ( [WholeName] <> "Alan Jones" ) AND ( [WholeName] <> "Alice Carter" ) ;"

If you see OR instead of AND in such a clause, edit the SQL to correct the text to AND. Then switch back to the query grid to see what it did to you. Don't bother to save anything until you have the AND in place rather than the OR in the SQL view of the query.

Let me guess... you tried this in a query grid, listed the names, and nobody got excluded, right? That is because the query grid is implicitly based on OR, not AND - but in this case you really wanted AND, not OR, so the query grid fooled you.
 

KenHigg

Registered User
Local time
Today, 16:57
Joined
Jun 9, 2004
Messages
13,327
Not like "Dave Smith" and Not like "Alan Jones" not like "Alice Carter"


???
ken
 

Mile-O

Back once again...
Local time
Today, 21:57
Joined
Dec 10, 2002
Messages
11,316
Not In("Name1", "Name2", "Name3", "etc.")
 

WayneRyan

AWF VIP
Local time
Today, 21:57
Joined
Nov 19, 2002
Messages
7,122
uplink,

Another variation:

Code:
Select SomeName
From   Table1
Where  SomeName Not In (
   Select SomeName
   From   Table2)

Wayne
 

EmilyTheChef

New member
Local time
Today, 14:57
Joined
Mar 8, 2012
Messages
3
Let me guess... you tried this in a query grid, listed the names, and nobody got excluded, right? That is because the query grid is implicitly based on OR, not AND - but in this case you really wanted AND, not OR, so the query grid fooled you.

THANK YOU The_Doc_Man - AND vs OR... brilliant! Solved a problem I've been :banghead: over for a few weeks.
 

Users who are viewing this thread

Top Bottom