I am trying to create a query which selects the record of each ID with a maximum value. I need to use 3 fields from my table:
1. ID (foreign key)
2. Variety
3. Acres
I want to select the record for each ID which has the most acres of a given variety. So if my table looks like this:
ID1 Blue 5
ID1 Red 3
ID1 Green 2
ID2 Red 10
ID2 Purple 15
I need it to return this:
ID1 Blue 5
ID2 Purple 15
I can create a query which returns the correct acreage but can't get it to display the name of the variety too...I get an "aggregate function" error. If I include use GroupBy to include Variety, the query no longer returns the Max, but returns all values.
Here is the query that doesn't include Variety name.
SELECT Varieties.ID, Max(Varieties.Acres) AS MaxOfAcres
FROM Varieties
GROUP BY Varieties.ID;
Any suggestions?
Thank you,
Eadie
1. ID (foreign key)
2. Variety
3. Acres
I want to select the record for each ID which has the most acres of a given variety. So if my table looks like this:
ID1 Blue 5
ID1 Red 3
ID1 Green 2
ID2 Red 10
ID2 Purple 15
I need it to return this:
ID1 Blue 5
ID2 Purple 15
I can create a query which returns the correct acreage but can't get it to display the name of the variety too...I get an "aggregate function" error. If I include use GroupBy to include Variety, the query no longer returns the Max, but returns all values.
Here is the query that doesn't include Variety name.
SELECT Varieties.ID, Max(Varieties.Acres) AS MaxOfAcres
FROM Varieties
GROUP BY Varieties.ID;
Any suggestions?
Thank you,
Eadie