Query with multiple Not In criteria

S

shall

I want to filter out names by using Not In. Some only with just last names
and also some with both Frist and Last Name.

What I have now is (which works great)...
WHERE (((MainInformation.LastName) Not In
("LastName1","LastName2","LastName3","Lastname4","LastName5")));

Can I somehow add in on the same or another line (this gives me the wrong
results)...

WHERE (((MainInformation.LastName) Not In
("LastName1","LastName2","LastName3","Lastname4","LastName5"))) OR
(((MainInformation.LastName) Not In ("LastName6")) AND
((MainInformation.FirstName) Not In ("FirstName6")));

I'm new at the SQL. Thanks for any help!
 
J

John Spencer

You probably need to replace the OR with AND

Also, since there is only one value to compare you could use <> (Not equal)
instead of Not In


WHERE (MainInformation.LastName Not In
("LastName1","LastName2","LastName3","Lastname4","LastName5") AND
(MainInformation.LastName <> "LastName6" AND MainInformation.FirstName <> "FirstName6")

Alternatively the logic could be expressed as

WHERE NOT ((MainInformation.LastName In
("LastName1","LastName2","LastName3","Lastname4","LastName5") OR
(MainInformation.LastName = "LastName6" AND MainInformation.FirstName = "FirstName6"))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top