MS Access Using Max on a Count

G

GraberJ

I am trying to get the Maximum Number of Parts associated with a
certain Supplier by an ID. What I've done so far is I've counted how
many Suppliers are associated with each ID. So my query has Supplier,
ID, and CountOfPartNbr (Original Table keyed by PartNbr, need to have
the ID that has the most Parts per supplier). I then took a 2nd query
and tried to get the Maximum number of suppliers (Max(CountOfSupplier))
for each ID by Supplier. What I want my final result to be is

ID Supplier
Jim Joe's Stuff
John Burger Joint

Assuming the original count was like this:

ID Supplier CountOfSupplier (If ID has parts
associated with this supplier)
Jim Joe's Stuff 9
John Joe's Stuff 4
Jim Burger Joint 5
John Burger Joint 8

However, when I use the Max function I get the 2nd table where it shows
everything. Like the Max isn't working. How can I get this to work?
 
K

KARL DEWEY

Two queries --
First named GraberJ-1
SELECT GraberJ.ID, Max(GraberJ.CountOfSupplier) AS MaxOfCountOfSupplier
FROM GraberJ
GROUP BY GraberJ.ID;

SELECT GraberJ.ID, GraberJ.Supplier
FROM GraberJ INNER JOIN [GraberJ-1] ON (GraberJ.CountOfSupplier =
[GraberJ-1].MaxOfCountOfSupplier) AND (GraberJ.ID = [GraberJ-1].ID);
 
G

GraberJ

Thanks for the reply. That worked and I'm up and running now.

KARL said:
Two queries --
First named GraberJ-1
SELECT GraberJ.ID, Max(GraberJ.CountOfSupplier) AS MaxOfCountOfSupplier
FROM GraberJ
GROUP BY GraberJ.ID;

SELECT GraberJ.ID, GraberJ.Supplier
FROM GraberJ INNER JOIN [GraberJ-1] ON (GraberJ.CountOfSupplier =
[GraberJ-1].MaxOfCountOfSupplier) AND (GraberJ.ID = [GraberJ-1].ID);


I am trying to get the Maximum Number of Parts associated with a
certain Supplier by an ID. What I've done so far is I've counted how
many Suppliers are associated with each ID. So my query has Supplier,
ID, and CountOfPartNbr (Original Table keyed by PartNbr, need to have
the ID that has the most Parts per supplier). I then took a 2nd query
and tried to get the Maximum number of suppliers (Max(CountOfSupplier))
for each ID by Supplier. What I want my final result to be is

ID Supplier
Jim Joe's Stuff
John Burger Joint

Assuming the original count was like this:

ID Supplier CountOfSupplier (If ID has parts
associated with this supplier)
Jim Joe's Stuff 9
John Joe's Stuff 4
Jim Burger Joint 5
John Burger Joint 8

However, when I use the Max function I get the 2nd table where it shows
everything. Like the Max isn't working. How can I get this to work?
 

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