Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem to output all fields using aggregate function 1

Status
Not open for further replies.

RinaGreen

Technical User
Mar 8, 2005
31
US
Hi everybody

I created the following SQL query and it does work except I need all other fields in the output.

select id,Max(dt_day)
FROM DenLab
GROUP BY id;

However I found out that whenever I add some of the other fields to select clause, it doesn't give me correct answer

for example:

select id, other field ,Max(dt_day)
FROM DenLab
GROUP BY id;

But I do need other fields!11

Is there any way to do it?

Thank you in advance

Rina
 
If you need only the values that go along with the max day.

Easiest in Access to use 2 queries.

select id, Max(dt_day) as mDay
FROM DenLab
GROUP BY id;

Save as qMaxDay.

select * from DenLab
Inner join qMaxDay
On qMaxDay.id = DenLab.id
and qMaxDay.mDay = DenLab.dt_day
 
you have to add all the fields in the SELECT clause to the GROUP BY clause:

select id, other field ,Max(dt_day)
FROM DenLab
GROUP BY id, other field;


Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top