Access query with one to many relationship

CliveButler

New Member
Joined
Jun 7, 2014
Messages
14
Hi Everyone,

I'm trying to workout the following. I have 2 tables see below.

There is a one to many relationship between table 1 ID to table 2 ID

What I want is to create a query to select ID number that does not contain any Item starting with B0 or C0

The answer this query should give me is ID103 and ID105

Can anyone help? I spend most of the day on this but not really getting anywhere.

Thanks


Table 1
ID
ID101
ID102
ID103
ID104

<tbody>
</tbody>
Table2
IDItem
ID101A01
ID101A01
ID101B01
ID101B02
ID102B02
ID102B02
ID103D01
ID103E01
ID103E02
ID104C01
ID104B04
ID104C03
ID105A01
ID105A02
ID105A03

<tbody>
</tbody>
 
Hi everyone,
Thanks for all the suggestions. Here is what ended up using that seems to be working ok

Code:
SELECT DISTINCT T1.ID
FROM TABLE1 AS T1 
LEFT JOIN (SELECT ID, ITEM FROM TABLE1 WHERE ITEM LIKE '[B][COLOR=#ff0000][B-C]*[/COLOR]'[/B])  AS T2 ON T1.ID = T2.ID
WHERE 
    (((T2.ID) Is Null));
This will exclude all items beginning with B or C. If you mean that its alright but as per your writing you wanted to exclude those IDs with items beginning with B0 or C0 which are two different things.
Try editing your query by inserting zero before the star (see red bolded above and below) OR you may consider trying this query below
Rich (BB code):
SELECT DISTINCT T1.ID
FROM T1 INNER JOIN T2 ON T1.ID = T2.ID
WHERE T1.ID NOT IN (SELECT DISTINCT T1.ID FROM T1 INNER JOIN T2 ON T1.ID = T2.ID WHERE T2.Item Like '[B-C]0*')
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
This will exclude all items beginning with B or C. If you mean that its alright but as per your writing you wanted to exclude those IDs with items beginning with B0 or C0 which are two different things.
Try editing your query by inserting zero before the star (see red bolded above and below) OR you may consider trying this query below
Rich (BB code):
SELECT DISTINCT T1.ID
FROM T1 INNER JOIN T2 ON T1.ID = T2.ID
WHERE T1.ID NOT IN (SELECT DISTINCT T1.ID FROM T1 INNER JOIN T2 ON T1.ID = T2.ID WHERE T2.Item Like '[B-C]0*')
Sorry! The first join bolded here is insignificant and can be omitted. No problem.
 
Upvote 0

Forum statistics

Threads
1,221,831
Messages
6,162,250
Members
451,757
Latest member
iours

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