Exclude Record if Text Found in another Field

screech

Active Member
Joined
May 27, 2004
Messages
296
Greetings all, I apologize in advance if this has been asked and answered before but my searching has not been successful.

I am attempting to create a query in Access. I have two fields in a table. Both fields contain text. I am trying to write a query that returns all the records for Field1 where the value for Field1 is not found anywhere in Field2.

For example:
Code:
Field1       Field2
Apples       Red
Apples       Green
Bananas      Yellow
Carrots      Orange
Fruit        Apples
Fruit        Bananas
Vegetable    Carrots

I would like the query to return the Field1 records:
Code:
Fruit
Vegetable
and exclude Apples, Bananas, and Carrots are found in Field2.

I thought that I can add a criteria to Field1 that says something like: Not [Field2] but I can't get the right criteria expression. Can you please help with the proper expression?
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
That is an odd structure (I have a feeling it may not be a normalized table). You would normally expect them to be in different tables instead instead of different fields within the same table.

However, you could do what you want like this:
Code:
SELECT DISTINCT Field1
FROM TableName
WHERE Field1 Not In 
(SELECT Field2 
FROM TableName);
 
Upvote 0
That is an odd structure (I have a feeling it may not be a normalized table). You would normally expect them to be in different tables instead instead of different fields within the same table.

However, you could do what you want like this:
Code:
SELECT DISTINCT Field1
FROM TableName
WHERE Field1 Not In 
(SELECT Field2 
FROM TableName);

Yes, it's definitely an odd structure. Parent items (Field1) have Child items (Field2) but then some of those Child items are also in Field1 since they are parents of other Child items in Field2... not simple to work with. Thank you for your solution -- it appears to be working for me. I appreciate the help.
 
Upvote 0

Forum statistics

Threads
1,221,531
Messages
6,160,364
Members
451,642
Latest member
mirofa

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