Re: Finding Max of a DB field and then return whole record grouping on one column

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Paul W Smith wrote:
I have a table as below:

X 210 5 TRUE A
Y 220 7 FALSE B
X 210 3 TRUE D
Y 219 1 TRUE B
Z 215 4 TRUE C
Z 212 5 FALSE D
X 209 1 TRUE A
Y 220 2 TRUE A
Z 221 3 TRUE B

What I am looking to return is the following, whether this by one complicated query or a series of Queries:

X 210 3 TRUE D
Y 220 2 TRUE A
Z 221 3 TRUE B

I am trying to group on the first column and then find the Max of the second column, and where this is equal, to use the record which has the Max of the third column.

I do not wish to use any custom VBA functions.



I'm not following your logic here:

Within X, max(col 2) is 210, within that, max(col 3) is 5 (not 3)
Within Y, max(col 2) is 220, within that, max(col 3) is 7 (not 2)
Within Z, max(col 2) is 221, within that, max(col 3) is 3 (ok fine)

Did you mean

> I am trying to group on the first column and then find the Max of the second
> column, and where this is equal, to use the record which has the /last/ of the
> third column.

Is so, can you ensure the order of the records is consistent? (Note: Selecting a table without ordering will not necessarily produce consistent results.)
.



Relevant Pages

  • Re: Help with chart
    ... Any idea on how to incorporate that into the chart? ... and datediff) as a second column. ... the third column would contain any field which would have non- ... You can also add a criteria to the first column with the ...
    (comp.databases.ms-access)
  • Re: please review my code
    ... thus spoke david: ... (setf (first column) ... (setf (second column) ... (setf (third column) ...
    (comp.lang.lisp)
  • Re: please review my code
    ... Stanisâaw Halik writes: ... (setf (first column) ... (setf (second column) ... (setf (third column) ...
    (comp.lang.lisp)
  • Re: Finding Max of a DB field and then return whole record grouping on one column
    ... I am trying to group on the first column and then find the Max of the ... second column, and where this is equal, to use the record which has the ... Max of the third column. ... Selecting a table without ordering will not necessarily produce consistent ...
    (microsoft.public.access.queries)
  • Re: please review my code
    ... pjb@xxxxxxxxxxxxxxxxx (Pascal J. Bourguignon) writes: ... (setf (first column) ... (setf (second column) ... (setf (third column) ...
    (comp.lang.lisp)