Access Query Logic Question

cmcreynolds

Active Member
Joined
May 21, 2015
Messages
295
Hello all, happy 2017!

I'm running a query in Access and I am filtering a field [product] for "M" or "D." There's a record for M and a record for D. However, some people have both. So, how can I put into the query "M or D but D if Both"?

I apologize if this is obvious. Long first day at work in 2017...

Thank you-

CMcReynolds
 
Last edited:

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
What do you mean by both? Does that mean one record with "MD"? Or does it mean two (or more) records, one with "M" and another with "D"?
 
Upvote 0
Ugh, I am not communicating clearly today. I apologize. There can be two records (but not necessarily) - one with "M" and one with "D"

(These are codes for degrees and I am looking for their higher if they have both a masters and a doctorate)
 
Upvote 0
Do an Aggregate Query, where you add the Employee Name and Degree field.
You will "Group By" Employee Name field, and take the "Min" of the Degree field.
 
Upvote 0
Correlated subquery approach is also possible (might perform less well if the dataset is large, otherwise should be okay):

Code:
select a.* from Table1 a
where a.[product] in ("M","D")
and not exists (select * from Table1 b where b.ID = a.ID and b.Product = "M" and a.Product = "D")

with Joe's solution, you can still get this into a query with more fields in the select clause by putting the results into a subquery:
Code:
select a.* from Table1 a
inner join 
	(
		select ID, max(product)
		from Table1
		group by ID
	)
	as b
on a.ID = b.ID

You can also take that whole subquery part and make a regular saved query out of it. sometimes MSAccess in particular performs better that way.
Code:
select a.* from Table1 a
inner join Query1 b
on a.ID = b.ID

I've assumed you have a primary key called ID. But you will have to substitute your real primary key in all the queries (and real table names, etc.).
 
Last edited:
Upvote 0
Well, I'm glad my own idea was represented :) (listed as your third). Anyway, thank you for everyone's help!
 
Upvote 0

Forum statistics

Threads
1,213,565
Messages
6,114,338
Members
448,570
Latest member
rik81h

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