Remove rows based on multiple fields

k_haj

New Member
Joined
Aug 25, 2016
Messages
5
I am looking to exclude a specific item from my query that is based on multiple fields. For example if I have a database of cars, greatly larger than shown below:

Make | Color

Ford | Red
Toyota | Blue
Chevy | Green
Ford | Black

I can't get Access to exclude only red and blue Fords.

My criteria is: Make: Not Like "Ford" | Color: Not Like "Red" And Not Like "Blue"

When I run the query it excludes all red and blue cars.

Any help is greatly appreciated! Thank you!
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
It makes more sense logically (to me anyway) to turn it into the negative form (where NOT):
Code:
select * from Table2 where not (Make = 'Ford' and Color in ('Red','Blue'))

But you can change it around using DeMorgan's Laws ........ not(x and y) is the same as (not x or not y) .......
Code:
select * from Table2 where (Make <> 'Ford' or Color not in ('Red','Blue'))
 
Last edited:
Upvote 0
This is the actual SQL:
WHERE ((([OppReport for US users].CAMPAIGN_NAME)<>"Ring") AND (([OppReport for US users].SALES_STAGE) Not Like "*captured*" And ([OppReport for US users].SALES_STAGE) Not Like "*confirmed*"))

This is the actual SQL. Of course I don't have a database of cars, but I want to exclude sales stages of captured or confirmed that have a campaign name of Brava Ring. Of course there are other campaign names and sales stages.

I used the car example as it is easier to understand.

Thank you for your help, I have been trying lots of variations but nothing works.
 
Upvote 0
xenou's query does this:

Table name is Data:


Excel 2010
AB
1CarColor
2FordRed
3ToyotaBlue
4ChevyGreen
5FordBlack
Sheet30


query in SQL is:

select * from Data where not (Car = 'Ford' and Color in ('Red','Blue'))

how it looks in design view:

pY5xD0X.png



result:


Excel 2010
AB
1CarColor
2ToyotaBlue
3ChevyGreen
4FordBlack
Sheet30
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,306
Members
449,079
Latest member
juggernaut24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top